From 2fa5eebe17744e1606ce8497cce2d8cea8a26ad3 Mon Sep 17 00:00:00 2001 From: leeyi Date: Sat, 1 Jul 2023 18:53:43 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20onReset/0,=20onSelecte?= =?UTF-8?q?d/2=20=E4=B8=A4=E4=B8=AA=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/pubspec.lock | 72 +++++++++++++------------- lib/src/filter_list_widget.dart | 18 +++++-- lib/src/widget/choice_list.dart | 6 +++ lib/src/widget/control_button_bar.dart | 8 ++- 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 07342c0..075133b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,48 +5,48 @@ packages: dependency: transitive description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 - url: "https://pub.dev" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.10.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" characters: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c - url: "https://pub.dev" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 - url: "https://pub.dev" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.17.0" + version: "1.17.1" cupertino_icons: dependency: "direct main" description: name: cupertino_icons sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.5" fake_async: @@ -54,7 +54,7 @@ packages: description: name: fake_async sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.1" filter_list: @@ -78,42 +78,42 @@ packages: dependency: transitive description: name: js - sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" - url: "https://pub.dev" + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.5" + version: "0.6.7" matcher: dependency: transitive description: name: matcher - sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" - url: "https://pub.dev" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.13" + version: "0.12.15" material_color_utilities: dependency: transitive description: name: material_color_utilities sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "0.2.0" meta: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" - url: "https://pub.dev" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0" + version: "1.9.1" path: dependency: transitive description: name: path - sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b - url: "https://pub.dev" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.2" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -124,7 +124,7 @@ packages: description: name: source_span sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.9.1" stack_trace: @@ -132,7 +132,7 @@ packages: description: name: stack_trace sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.11.0" stream_channel: @@ -140,7 +140,7 @@ packages: description: name: stream_channel sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" string_scanner: @@ -148,7 +148,7 @@ packages: description: name: string_scanner sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" term_glyph: @@ -156,25 +156,25 @@ packages: description: name: term_glyph sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 - url: "https://pub.dev" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.16" + version: "0.5.1" vector_math: dependency: transitive description: name: vector_math sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.4" sdks: - dart: ">=2.18.0 <4.0.0" + dart: ">=3.0.0-0 <4.0.0" flutter: ">=1.12.0" diff --git a/lib/src/filter_list_widget.dart b/lib/src/filter_list_widget.dart index 8a9a2b0..9224236 100644 --- a/lib/src/filter_list_widget.dart +++ b/lib/src/filter_list_widget.dart @@ -59,7 +59,7 @@ class FilterListWidget extends StatelessWidget { required this.validateSelectedItem, this.validateRemoveItem, required this.choiceChipLabel, - required this.onItemSearch, + this.onItemSearch, this.selectedListData, this.onApplyButtonClick, this.choiceChipBuilder, @@ -80,6 +80,8 @@ class FilterListWidget extends StatelessWidget { ControlButtonType.All, ControlButtonType.Reset ], + this.onReset, + this.onSelected, }) : super(key: key); /// Filter theme @@ -110,6 +112,10 @@ class FilterListWidget extends StatelessWidget { /// /// Default is `Navigator.pop(context, null)` final void Function()? onCloseWidgetPress; + /// + final void Function()? onReset; + /// + final void Function(T, bool)? onSelected; /// If true then it hide complete header section. final bool? hideHeader; @@ -130,7 +136,7 @@ class FilterListWidget extends StatelessWidget { final ValidateRemoveItem? validateRemoveItem; /// The `onItemSearch` is delegate which filter the list on the basis of search field text. - final SearchPredict onItemSearch; /*required*/ + final SearchPredict? onItemSearch; /*required*/ /// The `choiceChipLabel` is callback which required [String] value to display text on choice chip. final LabelDelegate choiceChipLabel; /*required*/ @@ -184,8 +190,10 @@ class FilterListWidget extends StatelessWidget { FilterState.of(context).items = listData; return; } - FilterState.of(context) - .filter((item) => onItemSearch(item, value)); + if (onItemSearch!=null) { + FilterState.of(context) + .filter((item) => onItemSearch!(item, value)); + } }, onCloseWidgetPress: onCloseWidgetPress, ), @@ -206,6 +214,7 @@ class FilterListWidget extends StatelessWidget { enableOnlySingleSelection: enableOnlySingleSelection, validateSelectedItem: validateSelectedItem, validateRemoveItem: validateRemoveItem, + onSelected: onSelected, ), ), ], @@ -218,6 +227,7 @@ class FilterListWidget extends StatelessWidget { applyButtonText: applyButtonText, resetButtonText: resetButtonText, enableOnlySingleSelection: enableOnlySingleSelection, + onReset:onReset, onApplyButtonClick: () { final selectedItems = FilterState.of(context).selectedItems; if (onApplyButtonClick != null) { diff --git a/lib/src/widget/choice_list.dart b/lib/src/widget/choice_list.dart index 10b0be4..654f192 100644 --- a/lib/src/widget/choice_list.dart +++ b/lib/src/widget/choice_list.dart @@ -12,12 +12,15 @@ class ChoiceList extends StatelessWidget { this.choiceChipLabel, this.enableOnlySingleSelection = false, this.validateRemoveItem, + this.onSelected, }) : super(key: key); final ValidateSelectedItem validateSelectedItem; final ChoiceChipBuilder? choiceChipBuilder; final LabelDelegate? choiceChipLabel; final bool enableOnlySingleSelection; final ValidateRemoveItem? validateRemoveItem; + /// + final void Function(T, bool)? onSelected; List _buildChoiceList(BuildContext context) { final theme = FilterListTheme.of(context).controlBarButtonTheme; @@ -51,6 +54,9 @@ class ChoiceList extends StatelessWidget { state.addSelectedItem(item); } } + if (onSelected != null) { + onSelected!(item, !selected); + } }, selected: selected, text: choiceChipLabel!(item), diff --git a/lib/src/widget/control_button_bar.dart b/lib/src/widget/control_button_bar.dart index bd52dd3..876edb9 100644 --- a/lib/src/widget/control_button_bar.dart +++ b/lib/src/widget/control_button_bar.dart @@ -1,7 +1,6 @@ import 'package:filter_list/filter_list.dart'; import 'package:filter_list/src/state/filter_state.dart'; import 'package:filter_list/src/state/provider.dart'; - import 'package:filter_list/src/widget/control_button.dart'; import 'package:flutter/material.dart'; @@ -13,6 +12,7 @@ class ControlButtonBar extends StatelessWidget { this.resetButtonText, this.applyButtonText, this.onApplyButtonClick, + this.onReset, required this.controlButtons, }) : super(key: key); final bool enableOnlySingleSelection; @@ -21,6 +21,9 @@ class ControlButtonBar extends StatelessWidget { final String? applyButtonText; final VoidCallback? onApplyButtonClick; + /// + final void Function()? onReset; + /// {@macro control_buttons} final List controlButtons; @@ -73,6 +76,9 @@ class ControlButtonBar extends StatelessWidget { rebuildOnChange: true, ); state.selectedItems = []; + if (onReset != null) { + onReset!(); + } }, ), SizedBox(width: theme.buttonSpacing), From 360a545706555c015d718d424deb805897013194 Mon Sep 17 00:00:00 2001 From: leeyi Date: Mon, 3 Jul 2023 11:34:47 +0800 Subject: [PATCH 2/4] Add custom header parameters to solve the problem of external components calling operation FilterState data --- lib/src/filter_list_widget.dart | 52 ++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/src/filter_list_widget.dart b/lib/src/filter_list_widget.dart index 9224236..25abdba 100644 --- a/lib/src/filter_list_widget.dart +++ b/lib/src/filter_list_widget.dart @@ -80,6 +80,7 @@ class FilterListWidget extends StatelessWidget { ControlButtonType.All, ControlButtonType.Reset ], + this.header, this.onReset, this.onSelected, }) : super(key: key); @@ -112,6 +113,8 @@ class FilterListWidget extends StatelessWidget { /// /// Default is `Navigator.pop(context, null)` final void Function()? onCloseWidgetPress; + + final Widget? header; /// final void Function()? onReset; /// @@ -169,6 +172,33 @@ class FilterListWidget extends StatelessWidget { /// {@endtemplate} final List controlButtons; + Widget _buildHeader(BuildContext context) { + if (header != null) { + return header!; + } + if (hideHeader!) { + return const SizedBox(); + } + return Header( + headlineText: headlineText, + hideSearchField: hideSearchField, + hideCloseIcon: hideCloseIcon, + headerCloseIcon: headerCloseIcon, + onSearch: (String value) { + if (value.isEmpty) { + FilterState + .of(context) + .items = listData; + return; + } + if (onItemSearch != null) { + FilterState.of(context) + .filter((item) => onItemSearch!(item, value)); + } + }, + onCloseWidgetPress: onCloseWidgetPress, + ); + } Widget _body(BuildContext context) { final theme = FilterListTheme.of(context); return Container( @@ -177,26 +207,7 @@ class FilterListWidget extends StatelessWidget { children: [ Column( children: [ - if (hideHeader!) - const SizedBox() - else - Header( - headlineText: headlineText, - hideSearchField: hideSearchField, - hideCloseIcon: hideCloseIcon, - headerCloseIcon: headerCloseIcon, - onSearch: (String value) { - if (value.isEmpty) { - FilterState.of(context).items = listData; - return; - } - if (onItemSearch!=null) { - FilterState.of(context) - .filter((item) => onItemSearch!(item, value)); - } - }, - onCloseWidgetPress: onCloseWidgetPress, - ), + _buildHeader(context), if (!hideSelectedTextCount) Padding( padding: const EdgeInsets.only(top: 5), @@ -262,4 +273,5 @@ class FilterListWidget extends StatelessWidget { ), ); } + } From 4331d0bb0f4eee0749c65dbb7258915ae4ea89ea Mon Sep 17 00:00:00 2001 From: leeyi Date: Wed, 1 Nov 2023 09:53:40 +0800 Subject: [PATCH 3/4] fix --- lib/src/filter_list_widget.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/filter_list_widget.dart b/lib/src/filter_list_widget.dart index 31879a0..51588a3 100644 --- a/lib/src/filter_list_widget.dart +++ b/lib/src/filter_list_widget.dart @@ -146,7 +146,7 @@ class FilterListWidget extends StatelessWidget { final ValidateRemoveItem? validateRemoveItem; /// The `onItemSearch` is delegate which filter the list on the basis of search field text. - final SearchPredict? onItemSearch; /*required*/ + final SearchPredict? onItemSearch; /// The `choiceChipLabel` is callback which required [String] value to display text on choice chip. final LabelDelegate choiceChipLabel; /*required*/ From 51bc889edd83c29b5da50dfc0c8d3fa8fce4df97 Mon Sep 17 00:00:00 2001 From: leeyi Date: Wed, 1 Nov 2023 09:55:36 +0800 Subject: [PATCH 4/4] fix --- example/pubspec.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 6eb4242..53c14bb 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -14,7 +14,7 @@ packages: description: name: boolean_selector sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "2.1.1" characters: @@ -30,7 +30,7 @@ packages: description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "1.1.1" collection: @@ -54,7 +54,7 @@ packages: description: name: fake_async sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "1.3.1" filter_list: @@ -124,7 +124,7 @@ packages: description: name: stack_trace sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "1.11.0" stream_channel: @@ -132,7 +132,7 @@ packages: description: name: stream_channel sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "2.1.1" string_scanner: @@ -140,7 +140,7 @@ packages: description: name: string_scanner sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "1.2.0" term_glyph: @@ -148,7 +148,7 @@ packages: description: name: term_glyph sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "1.2.1" test_api: @@ -164,7 +164,7 @@ packages: description: name: vector_math sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.flutter-io.cn" + url: "https://pub.dev" source: hosted version: "2.1.4" web: