aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/common/basic/list_tiles
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/widgets/common/basic/list_tiles
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/widgets/common/basic/list_tiles')
-rw-r--r--lib/widgets/common/basic/list_tiles/color.dart99
-rw-r--r--lib/widgets/common/basic/list_tiles/reselectable_radio.dart89
-rw-r--r--lib/widgets/common/basic/list_tiles/slider.dart71
3 files changed, 259 insertions, 0 deletions
diff --git a/lib/widgets/common/basic/list_tiles/color.dart b/lib/widgets/common/basic/list_tiles/color.dart
new file mode 100644
index 0000000..93d2e2a
--- /dev/null
+++ b/lib/widgets/common/basic/list_tiles/color.dart
@@ -0,0 +1,99 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/widgets/common/basic/color_indicator.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flex_color_picker/flex_color_picker.dart' show ColorPicker, ColorPickerType;
+import 'package:flutter/material.dart';
+
+class ColorListTile extends StatelessWidget {
+ final String title;
+ final Color value;
+ final ValueSetter<Color> onChanged;
+
+ const ColorListTile({
+ super.key,
+ required this.title,
+ required this.value,
+ required this.onChanged,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return ListTile(
+ title: Text(title),
+ trailing: ColorIndicator(
+ value: value,
+ ),
+ contentPadding: const EdgeInsetsDirectional.only(start: 16, end: 36 - ColorIndicator.radius),
+ onTap: () async {
+ final color = await showDialog<Color>(
+ context: context,
+ builder: (context) => ColorPickerDialog(
+ initialValue: value,
+ ),
+ routeSettings: const RouteSettings(name: ColorPickerDialog.routeName),
+ );
+ if (color != null) {
+ onChanged(color);
+ }
+ },
+ );
+ }
+}
+
+class ColorPickerDialog extends StatefulWidget {
+ static const routeName = '/dialog/pick_color';
+
+ final Color initialValue;
+
+ const ColorPickerDialog({
+ super.key,
+ required this.initialValue,
+ });
+
+ @override
+ State<ColorPickerDialog> createState() => _ColorPickerDialogState();
+}
+
+class _ColorPickerDialogState extends State<ColorPickerDialog> {
+ late Color color;
+
+ @override
+ void initState() {
+ super.initState();
+ color = widget.initialValue;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final useTvLayout = settings.useTvLayout;
+ return AvesDialog(
+ scrollableContent: [
+ ColorPicker(
+ color: color,
+ onColorChanged: (v) => color = v,
+ pickersEnabled: useTvLayout
+ ? const {
+ ColorPickerType.primary: true,
+ ColorPickerType.accent: false,
+ }
+ : const {
+ ColorPickerType.primary: false,
+ ColorPickerType.accent: false,
+ ColorPickerType.wheel: true,
+ },
+ hasBorder: true,
+ borderRadius: 20,
+ subheading: useTvLayout ? const SizedBox(height: 16) : null,
+ )
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(color),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/widgets/common/basic/list_tiles/reselectable_radio.dart b/lib/widgets/common/basic/list_tiles/reselectable_radio.dart
new file mode 100644
index 0000000..1f937da
--- /dev/null
+++ b/lib/widgets/common/basic/list_tiles/reselectable_radio.dart
@@ -0,0 +1,89 @@
+import 'package:flutter/material.dart';
+
+// `RadioListTile` that can trigger `onChanged` on tap when already selected, if `reselectable` is true
+class ReselectableRadioListTile<T> extends StatelessWidget {
+ final T value;
+ final T groupValue;
+ final ValueChanged<T?>? onChanged;
+ final bool toggleable;
+ final bool reselectable;
+ final Color? activeColor;
+ final Widget? title;
+ final Widget? subtitle;
+ final Widget? secondary;
+ final bool isThreeLine;
+ final bool? dense;
+ final bool selected;
+ final ListTileControlAffinity controlAffinity;
+ final bool autofocus;
+
+ bool get checked => value == groupValue;
+
+ const ReselectableRadioListTile({
+ super.key,
+ required this.value,
+ required this.groupValue,
+ required this.onChanged,
+ this.toggleable = false,
+ this.reselectable = false,
+ this.activeColor,
+ this.title,
+ this.subtitle,
+ this.isThreeLine = false,
+ this.dense,
+ this.secondary,
+ this.selected = false,
+ this.controlAffinity = ListTileControlAffinity.platform,
+ this.autofocus = false,
+ }) : assert(!isThreeLine || subtitle != null);
+
+ @override
+ Widget build(BuildContext context) {
+ final Widget control = Radio<T>(
+ value: value,
+ groupValue: groupValue,
+ onChanged: onChanged,
+ toggleable: toggleable,
+ activeColor: activeColor,
+ materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ autofocus: autofocus,
+ );
+ Widget? leading, trailing;
+ switch (controlAffinity) {
+ case ListTileControlAffinity.leading:
+ case ListTileControlAffinity.platform:
+ leading = control;
+ trailing = secondary;
+ case ListTileControlAffinity.trailing:
+ leading = secondary;
+ trailing = control;
+ }
+ return MergeSemantics(
+ child: ListTileTheme.merge(
+ selectedColor: activeColor ?? Theme.of(context).colorScheme.primary,
+ child: ListTile(
+ leading: leading,
+ title: title,
+ subtitle: subtitle,
+ trailing: trailing,
+ isThreeLine: isThreeLine,
+ dense: dense,
+ enabled: onChanged != null,
+ onTap: onChanged != null
+ ? () {
+ if (toggleable && checked) {
+ onChanged!(null);
+ return;
+ }
+ if (reselectable || !checked) {
+ onChanged!(value);
+ }
+ }
+ : null,
+ selected: selected,
+ autofocus: autofocus,
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/common/basic/list_tiles/slider.dart b/lib/widgets/common/basic/list_tiles/slider.dart
new file mode 100644
index 0000000..1a95a2e
--- /dev/null
+++ b/lib/widgets/common/basic/list_tiles/slider.dart
@@ -0,0 +1,71 @@
+import 'package:flutter/material.dart';
+
+class SliderListTile extends StatelessWidget {
+ final String title;
+ final double value;
+ final ValueChanged<double>? onChanged;
+ final double min;
+ final double max;
+ final int? divisions;
+ final EdgeInsetsGeometry titlePadding;
+ final Widget Function(BuildContext context, double value)? titleTrailing;
+
+ const SliderListTile({
+ super.key,
+ required this.title,
+ required this.value,
+ required this.onChanged,
+ this.min = 0.0,
+ this.max = 1.0,
+ this.divisions,
+ this.titlePadding = const EdgeInsetsDirectional.only(start: 16),
+ this.titleTrailing,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ final listTileTitleTextStyle = ListTileTheme.of(context).titleTextStyle ?? theme.textTheme.bodyLarge!.copyWith(color: theme.colorScheme.onSurface);
+ return SliderTheme(
+ data: SliderTheme.of(context).copyWith(
+ overlayShape: const RoundSliderOverlayShape(
+ // align `Slider`s on `Switch`es by matching their overlay/reaction radius
+ // `kRadialReactionRadius` is used when `SwitchThemeData.splashRadius` is undefined
+ overlayRadius: kRadialReactionRadius,
+ ),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.only(top: 16, bottom: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: titlePadding,
+ child: Row(
+ children: [
+ Text(
+ title,
+ style: listTileTitleTextStyle,
+ ),
+ const Spacer(),
+ if (titleTrailing != null) titleTrailing!(context, value),
+ ],
+ ),
+ ),
+ Padding(
+ // match `SwitchListTile.contentPadding`
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Slider(
+ value: value,
+ onChanged: onChanged,
+ min: min,
+ max: max,
+ divisions: divisions,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}