From 4d1301f8e44463db1f5bed7a4ad1dc3a0fa65f11 Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 11:02:28 -0300 Subject: [PATCH 1/9] changes to allow prevent closing modal --- lib/dialog/mult_select_dialog.dart | 2 +- lib/util/multi_select_actions.dart | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index 433539f..7c11c42 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -18,7 +18,7 @@ class MultiSelectDialog extends StatefulWidget with MultiSelectActions { final void Function(List)? onSelectionChanged; /// Fires when confirm is tapped. - final void Function(List)? onConfirm; + final bool? Function(List)? onConfirm; /// Toggles search functionality. Default is false. final bool searchable; diff --git a/lib/util/multi_select_actions.dart b/lib/util/multi_select_actions.dart index d8ad5e0..be1d233 100644 --- a/lib/util/multi_select_actions.dart +++ b/lib/util/multi_select_actions.dart @@ -20,12 +20,19 @@ class MultiSelectActions { /// Pops the dialog from the navigation stack and returns the selected values. /// Calls the onConfirm function if one was provided. - void onConfirmTap( - BuildContext ctx, List selectedValues, Function(List)? onConfirm) { - Navigator.pop(ctx, selectedValues); - if (onConfirm != null) { - onConfirm(selectedValues); - } + void onConfirmTap + ( + BuildContext ctx, List selectedValues, bool? Function(List)? onConfirm) + { + bool shouldClose = true; + + if (onConfirm != null) + { + shouldClose = onConfirm(selectedValues); + } + + if (shouldClose) + Navigator.pop(ctx, selectedValues); } /// Accepts the search query, and the original list of items. From 72605952a4fbb1120ddd57cf47c5a13a38389d44 Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 11:07:52 -0300 Subject: [PATCH 2/9] added bool? as return type for onConfirm event --- lib/bottom_sheet/multi_select_bottom_sheet.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottom_sheet/multi_select_bottom_sheet.dart b/lib/bottom_sheet/multi_select_bottom_sheet.dart index 9af4af8..4021eb1 100644 --- a/lib/bottom_sheet/multi_select_bottom_sheet.dart +++ b/lib/bottom_sheet/multi_select_bottom_sheet.dart @@ -19,7 +19,7 @@ class MultiSelectBottomSheet extends StatefulWidget final void Function(List)? onSelectionChanged; /// Fires when confirm is tapped. - final void Function(List)? onConfirm; + final bool? Function(List)? onConfirm; /// Toggles search functionality. final bool searchable; From 5d51c50c4034cf7ce86dbd534f59cf2103ce16e0 Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 11:12:11 -0300 Subject: [PATCH 3/9] Smallfix --- lib/util/multi_select_actions.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util/multi_select_actions.dart b/lib/util/multi_select_actions.dart index be1d233..db5bfda 100644 --- a/lib/util/multi_select_actions.dart +++ b/lib/util/multi_select_actions.dart @@ -24,15 +24,15 @@ class MultiSelectActions { ( BuildContext ctx, List selectedValues, bool? Function(List)? onConfirm) { - bool shouldClose = true; + bool? shouldClose = true; if (onConfirm != null) { shouldClose = onConfirm(selectedValues); } - if (shouldClose) - Navigator.pop(ctx, selectedValues); + if (shouldClose == null || shouldClose == true) + Navigator.pop(ctx, selectedValues); } /// Accepts the search query, and the original list of items. From e79f520fa42f19c4460b74b2a0a1d90a4e50e85c Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 11:14:17 -0300 Subject: [PATCH 4/9] final commit --- lib/util/multi_select_actions.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/util/multi_select_actions.dart b/lib/util/multi_select_actions.dart index db5bfda..eec6359 100644 --- a/lib/util/multi_select_actions.dart +++ b/lib/util/multi_select_actions.dart @@ -32,7 +32,9 @@ class MultiSelectActions { } if (shouldClose == null || shouldClose == true) + { Navigator.pop(ctx, selectedValues); + } } /// Accepts the search query, and the original list of items. From 8473de1768e370b986277a40eab6e7ea7d0e1f59 Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 20:40:30 -0300 Subject: [PATCH 5/9] Attempt to repaint selected items --- .../multi_select_bottom_sheet.dart | 2 +- lib/dialog/mult_select_dialog.dart | 23 ++++ pubspec.lock | 114 +++++++++++++----- 3 files changed, 106 insertions(+), 33 deletions(-) diff --git a/lib/bottom_sheet/multi_select_bottom_sheet.dart b/lib/bottom_sheet/multi_select_bottom_sheet.dart index 4021eb1..e356235 100644 --- a/lib/bottom_sheet/multi_select_bottom_sheet.dart +++ b/lib/bottom_sheet/multi_select_bottom_sheet.dart @@ -10,7 +10,7 @@ class MultiSelectBottomSheet extends StatefulWidget final List> items; /// The list of selected values before interaction. - final List initialValue; + List initialValue; /// The text at the top of the BottomSheet. final Widget? title; diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index 7c11c42..1e89e25 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -121,6 +121,8 @@ class _MultiSelectDialogState extends State> { super.initState(); _selectedValues.addAll(widget.initialValue); + print('_selectedValues.length: ${_selectedValues.length}'); + for (int i = 0; i < _items.length; i++) { _items[i].selected = false; if (_selectedValues.contains(_items[i].value)) { @@ -133,6 +135,26 @@ class _MultiSelectDialogState extends State> { } } + repaintSelectedItems() + { + print('_selectedValues.length: ${_selectedValues.length}'); + + List> items = []; + + for (int i = 0; i < _items.length; i++) { + _items[i].selected = false; + if (_selectedValues.contains(_items[i].value)) { + _items[i].selected = true; + } + } + + items = _items; + + setState(() { + _items = items; + }); + } + /// Returns a CheckboxListTile Widget _buildListItem(MultiSelectItem item) { return Theme( @@ -216,6 +238,7 @@ class _MultiSelectDialogState extends State> { @override Widget build(BuildContext context) { + repaintSelectedItems(); return AlertDialog( backgroundColor: widget.backgroundColor, title: widget.searchable == false diff --git a/pubspec.lock b/pubspec.lock index 8a01ee3..8a48d77 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,42 +5,48 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.9.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: "direct main" description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted version: "1.3.1" flutter: @@ -53,34 +59,62 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" source: hosted - version: "0.12.12" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.11.1" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.15.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -90,50 +124,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + url: "https://pub.dev" source: hosted - version: "0.4.12" + version: "0.7.2" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + url: "https://pub.dev" + source: hosted + version: "14.2.5" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" From 62bdfe87b3478496617de49f24078781e8c64685 Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 20:48:05 -0300 Subject: [PATCH 6/9] . --- lib/dialog/mult_select_dialog.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index 1e89e25..d2c2088 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -121,7 +121,7 @@ class _MultiSelectDialogState extends State> { super.initState(); _selectedValues.addAll(widget.initialValue); - print('_selectedValues.length: ${_selectedValues.length}'); + print('initState._selectedValues.length: ${_selectedValues.length}'); for (int i = 0; i < _items.length; i++) { _items[i].selected = false; @@ -137,7 +137,8 @@ class _MultiSelectDialogState extends State> { repaintSelectedItems() { - print('_selectedValues.length: ${_selectedValues.length}'); + print('repaintSelectedItems._selectedValues.length: ${_selectedValues.length}'); + print('repaintSelectedItems._items.length: ${_items.length}'); List> items = []; @@ -238,6 +239,7 @@ class _MultiSelectDialogState extends State> { @override Widget build(BuildContext context) { + print('build.multi_select_dialog'); repaintSelectedItems(); return AlertDialog( backgroundColor: widget.backgroundColor, From 9378ea9431f8f95b1df7b13e0c1a3931e3ee0a7b Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 21:00:08 -0300 Subject: [PATCH 7/9] . --- lib/dialog/mult_select_dialog.dart | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index d2c2088..c021c40 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -121,11 +121,10 @@ class _MultiSelectDialogState extends State> { super.initState(); _selectedValues.addAll(widget.initialValue); - print('initState._selectedValues.length: ${_selectedValues.length}'); - for (int i = 0; i < _items.length; i++) { _items[i].selected = false; if (_selectedValues.contains(_items[i].value)) { + print('found matching element: ${_items[i].label}'); _items[i].selected = true; } } @@ -135,27 +134,6 @@ class _MultiSelectDialogState extends State> { } } - repaintSelectedItems() - { - print('repaintSelectedItems._selectedValues.length: ${_selectedValues.length}'); - print('repaintSelectedItems._items.length: ${_items.length}'); - - List> items = []; - - for (int i = 0; i < _items.length; i++) { - _items[i].selected = false; - if (_selectedValues.contains(_items[i].value)) { - _items[i].selected = true; - } - } - - items = _items; - - setState(() { - _items = items; - }); - } - /// Returns a CheckboxListTile Widget _buildListItem(MultiSelectItem item) { return Theme( @@ -239,8 +217,6 @@ class _MultiSelectDialogState extends State> { @override Widget build(BuildContext context) { - print('build.multi_select_dialog'); - repaintSelectedItems(); return AlertDialog( backgroundColor: widget.backgroundColor, title: widget.searchable == false From e4b8530a9aba348a75bab10f29856628ab821bff Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 21:04:51 -0300 Subject: [PATCH 8/9] x --- lib/dialog/mult_select_dialog.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index c021c40..68d922b 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -121,8 +121,15 @@ class _MultiSelectDialogState extends State> { super.initState(); _selectedValues.addAll(widget.initialValue); + print('_selectedValues: ${_selectedValues.length}'); + for (int i = 0; i < _selectedValues.length; i++) { + print('_selectedValues[${i}]: ${_selectedValues[i]}'); + } + print('....'); for (int i = 0; i < _items.length; i++) { _items[i].selected = false; + print('_items[${i}].value : ${_items[i].value}'); + if (_selectedValues.contains(_items[i].value)) { print('found matching element: ${_items[i].label}'); _items[i].selected = true; From e659c8ccb058533a0ccddad9c7ea310138e705d1 Mon Sep 17 00:00:00 2001 From: Matias Bello Date: Mon, 28 Oct 2024 22:10:59 -0300 Subject: [PATCH 9/9] Back to original --- lib/dialog/mult_select_dialog.dart | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index 68d922b..7c11c42 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -121,17 +121,9 @@ class _MultiSelectDialogState extends State> { super.initState(); _selectedValues.addAll(widget.initialValue); - print('_selectedValues: ${_selectedValues.length}'); - for (int i = 0; i < _selectedValues.length; i++) { - print('_selectedValues[${i}]: ${_selectedValues[i]}'); - } - print('....'); for (int i = 0; i < _items.length; i++) { _items[i].selected = false; - print('_items[${i}].value : ${_items[i].value}'); - if (_selectedValues.contains(_items[i].value)) { - print('found matching element: ${_items[i].label}'); _items[i].selected = true; } }