summaryrefslogtreecommitdiff
path: root/lib/widgets/dialogs/selection_dialogs/multi_selection.dart
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/dialogs/selection_dialogs/multi_selection.dart
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/dialogs/selection_dialogs/multi_selection.dart')
-rw-r--r--lib/widgets/dialogs/selection_dialogs/multi_selection.dart91
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/widgets/dialogs/selection_dialogs/multi_selection.dart b/lib/widgets/dialogs/selection_dialogs/multi_selection.dart
new file mode 100644
index 0000000..a9079b3
--- /dev/null
+++ b/lib/widgets/dialogs/selection_dialogs/multi_selection.dart
@@ -0,0 +1,91 @@
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/common.dart';
+import 'package:flutter/material.dart';
+
+class AvesMultiSelectionDialog<T> extends StatefulWidget {
+ static const routeName = '/dialog/multi_selection';
+
+ final Set<T> initialValue;
+ final Map<T, String> options;
+ final TextBuilder<T>? optionSubtitleBuilder;
+ final String? title, message;
+ final bool? dense;
+
+ const AvesMultiSelectionDialog({
+ super.key,
+ required this.initialValue,
+ required this.options,
+ this.optionSubtitleBuilder,
+ this.title,
+ this.message,
+ this.dense,
+ });
+
+ @override
+ State<AvesMultiSelectionDialog<T>> createState() => _AvesMultiSelectionDialogState<T>();
+}
+
+class _AvesMultiSelectionDialogState<T> extends State<AvesMultiSelectionDialog<T>> {
+ late Set<T> _selectedValues;
+
+ @override
+ void initState() {
+ super.initState();
+ _selectedValues = widget.initialValue;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final title = widget.title;
+ final message = widget.message;
+ final verticalPadding = (title == null && message == null) ? AvesDialog.cornerRadius.y / 2 : .0;
+ return AvesDialog(
+ title: title,
+ scrollableContent: [
+ if (verticalPadding != 0) SizedBox(height: verticalPadding),
+ if (message != null)
+ Padding(
+ padding: const EdgeInsets.all(16),
+ child: Text(message),
+ ),
+ ...widget.options.entries.map((kv) {
+ final value = kv.key;
+ final title = kv.value;
+ final subtitle = widget.optionSubtitleBuilder?.call(value);
+ return SwitchListTile(
+ value: _selectedValues.contains(value),
+ onChanged: (v) {
+ if (v) {
+ _selectedValues.add(value);
+ } else {
+ _selectedValues.remove(value);
+ }
+ setState(() {});
+ },
+ title: Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: Text(title),
+ ),
+ subtitle: subtitle != null
+ ? Text(
+ subtitle,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ )
+ : null,
+ dense: widget.dense,
+ );
+ }),
+ if (verticalPadding != 0) SizedBox(height: verticalPadding),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(widget.options.keys.where(_selectedValues.contains).toList()),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+}