adguard-home-manager/lib/widgets/custom_list_tile.dart

100 lines
3.4 KiB
Dart
Raw Normal View History

2022-10-20 02:42:25 +02:00
import 'package:flutter/material.dart';
class CustomListTile extends StatelessWidget {
final String title;
final String? subtitle;
2022-10-22 03:16:08 +02:00
final Widget? subtitleWidget;
2022-10-21 02:06:53 +02:00
final void Function()? onTap;
2022-10-20 02:42:25 +02:00
final IconData? icon;
2022-10-21 02:06:53 +02:00
final Widget? trailing;
final EdgeInsets? padding;
final void Function()? onLongPress;
2023-02-04 20:50:14 +01:00
final bool? disabled;
2023-05-01 21:34:00 +02:00
final void Function(bool)? onHover;
2022-10-20 02:42:25 +02:00
const CustomListTile({
Key? key,
required this.title,
this.subtitle,
2022-10-22 03:16:08 +02:00
this.subtitleWidget,
2022-10-21 02:06:53 +02:00
this.onTap,
2022-10-20 02:42:25 +02:00
this.icon,
2022-10-21 02:06:53 +02:00
this.trailing,
this.padding,
2023-02-04 20:50:14 +01:00
this.onLongPress,
2023-05-01 21:34:00 +02:00
this.disabled,
this.onHover
2022-10-20 02:42:25 +02:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
2023-05-01 21:34:00 +02:00
onHover: onHover,
onLongPress: onLongPress,
2022-10-20 02:42:25 +02:00
child: Padding(
2022-11-04 22:56:00 +01:00
padding: padding ?? const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
2022-10-20 02:42:25 +02:00
child: Row(
2022-10-21 12:33:22 +02:00
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2022-10-20 02:42:25 +02:00
children: [
2022-10-21 02:06:53 +02:00
Flexible(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
Icon(
icon,
size: 24,
2023-02-04 20:50:14 +01:00
color: disabled == true
? Theme.of(context).colorScheme.onSurface.withOpacity(0.38)
: Theme.of(context).listTileTheme.iconColor,
2022-10-20 02:42:25 +02:00
),
const SizedBox(width: 16),
2022-10-21 02:06:53 +02:00
],
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
2022-11-04 17:04:25 +01:00
style: TextStyle(
fontSize: 16,
2022-11-04 17:04:25 +01:00
fontWeight: FontWeight.w400,
2023-02-04 20:50:14 +01:00
color: disabled == true
? Theme.of(context).colorScheme.onSurface.withOpacity(0.38)
: Theme.of(context).colorScheme.onSurface,
2022-10-21 02:06:53 +02:00
),
),
2022-10-22 03:16:08 +02:00
if (subtitle != null || subtitleWidget != null) ...[
2022-10-21 02:06:53 +02:00
const SizedBox(height: 5),
2022-10-22 03:16:08 +02:00
if (subtitle == null && subtitleWidget != null) subtitleWidget!,
if (subtitle != null && subtitleWidget == null) Text(
2022-10-21 02:06:53 +02:00
subtitle!,
style: TextStyle(
2023-02-04 20:50:14 +01:00
color: disabled == true
? Theme.of(context).colorScheme.onSurfaceVariant.withOpacity(0.38)
: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
fontWeight: FontWeight.w400
2022-10-21 02:06:53 +02:00
),
),
]
],
2022-10-20 02:42:25 +02:00
),
2022-10-21 02:06:53 +02:00
)
],
),
),
if (trailing != null) ...[
2023-03-16 23:29:18 +01:00
const SizedBox(width: 16),
2022-10-21 02:06:53 +02:00
trailing!
]
2022-10-20 02:42:25 +02:00
],
),
),
),
);
}
}