From d44ec9036c4de42e5b2893bca485f0e44301998e Mon Sep 17 00:00:00 2001 From: dali Date: Sun, 18 Jul 2021 11:05:13 +0100 Subject: [PATCH] #53 * update pubspec,changelog,readme * format files --- CHANGELOG.md | 2 ++ README.md | 31 +++++++++++++++++++++--- example/pubspec.lock | 2 +- lib/src/common/state_group.dart | 9 +++---- lib/src/controller/base_controller.dart | 2 ++ lib/src/controller/group_controller.dart | 8 +++--- pubspec.yaml | 2 +- test/checkbox_grouped_test.dart | 1 - test/custom_grouped_checkbox_test.dart | 14 +++++------ 9 files changed, 49 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58a891c..2644283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## [1.6.0] - add styles for SimpleGroupedCheckbox,SimpleGroupedChips,SimpleGroupedSwitch +* create new methods in GroupController :`select`,`selectValues`,`selectAll`,`deselectValues` and `deselectAll` ## [1.5.0] - add styles for SimpleGroupedCheckbox,SimpleGroupedChips,SimpleGroupedSwitch * create new generic `GroupedStyle` to manage style of simple_grouped_checkbox * deprecate `backgroundColorItem`,`selectedColorItem`,`textColor`,`selectedTextColor`,`selectedIcon`,`disabledColor` diff --git a/README.md b/README.md index 4f48d0c..242a9c4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # checkbox_grouped -![pub](https://img.shields.io/badge/pub-v1.5.0-orange) ![GitHub](https://img.shields.io/github/license/liodali/checkbox_grouped) +![pub](https://img.shields.io/badge/pub-v1.6.0-blue) ![GitHub](https://img.shields.io/github/license/liodali/checkbox_grouped) * grouped (checkbox/radioButton) * customisable grouped checkbox @@ -9,6 +9,7 @@ * make multiple selection * dialogGroupedCheckbox * list of groupedCheckbox + * select/deselect items pragrammatically ## Getting Started checkboxGrouped examples
@@ -19,7 +20,7 @@ Add the following to your `pubspec.yaml` file: dependencies: - checkbox_grouped: ^1.5.0 + checkbox_grouped: ^1.6.0 @@ -38,7 +39,6 @@ Add the following to your `pubspec.yaml` file: ) ), checkFirstElement: false, - multiSelection: false, ) ``` ### Declare GroupController to get selection and enabled/disabled Items @@ -98,6 +98,31 @@ controller.listen((v) { print("$v"); }); ``` +### select/selectValues +> select one item in single selection or multiple selection + +> selectValues work only in group when isMultiSelection is true + +```dart +controller.select(value); +or +controller.selectValues([value]); +``` + +### selectAll/selectValues +> select all or some items in multiple selection group +```dart +controller.selectAll(); +or +controller.selectValues([values]); +``` +### deselectAll/deselectValues +> deselect all or some items in multiple selection group +```dart +controller.deselectAll(); +or +controller.deselectValues([values]); +``` #### NOTICE diff --git a/example/pubspec.lock b/example/pubspec.lock index 4809585..a22a552 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -42,7 +42,7 @@ packages: path: ".." relative: true source: path - version: "1.5.0" + version: "1.6.0" clock: dependency: transitive description: diff --git a/lib/src/common/state_group.dart b/lib/src/common/state_group.dart index 7cacb1c..4c3d218 100644 --- a/lib/src/common/state_group.dart +++ b/lib/src/common/state_group.dart @@ -216,8 +216,6 @@ abstract class StateGroup extends State }); } - - void selectValues(List values) { values.forEach((value) { final key = values.indexOf(value); @@ -230,14 +228,15 @@ abstract class StateGroup extends State .where((element) => !selectionsValue.value.contains(element)) .toList()); } + void deselectValues(List values) { values.forEach((value) { final key = values.indexOf(value); notifierItems[key].value = notifierItems[key].value.copy( - checked: false, - ); + checked: false, + ); }); selectionsValue.value = List.from(selectionsValue.value) - ..removeWhere((ele)=>values.contains(ele)); + ..removeWhere((ele) => values.contains(ele)); } } diff --git a/lib/src/controller/base_controller.dart b/lib/src/controller/base_controller.dart index dbd9ce0..88d5a04 100644 --- a/lib/src/controller/base_controller.dart +++ b/lib/src/controller/base_controller.dart @@ -24,9 +24,11 @@ abstract class BaseController { /// /// [itemsValues] : (List) values that will be disabled void disabledItemsByValues(List itemsValues); + /// select one item in group ( singeSelection/multiple selection) /// [value] : (dynamic) value of item that should selected void select(K value); + /// select all items in group void selectAll(); diff --git a/lib/src/controller/group_controller.dart b/lib/src/controller/group_controller.dart index 04820de..5565bca 100644 --- a/lib/src/controller/group_controller.dart +++ b/lib/src/controller/group_controller.dart @@ -88,14 +88,14 @@ class GroupController implements BaseController { _widgetState.notifierItems[index].value.copy( checked: true, ); - if(_widgetState.selectedValue.value != null) { + if (_widgetState.selectedValue.value != null) { final indexOld = - _widgetState.values.indexOf(_widgetState.selectedValue.value); + _widgetState.values.indexOf(_widgetState.selectedValue.value); if (indexOld != -1) { _widgetState.notifierItems[indexOld].value = _widgetState.notifierItems[indexOld].value.copy( - checked: false, - ); + checked: false, + ); } } _widgetState.selectedValue.value = value; diff --git a/pubspec.yaml b/pubspec.yaml index dbacd74..1d41bf8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: checkbox_grouped description: flutter widget that grouping checkbox, recuperate the actual selection,support multiple selection -version: 1.5.0 +version: 1.6.0 homepage: https://github.com/liodali/grouped_checkbox authors: - Mohamed ali hamza diff --git a/test/checkbox_grouped_test.dart b/test/checkbox_grouped_test.dart index 13fb278..5a67c8a 100644 --- a/test/checkbox_grouped_test.dart +++ b/test/checkbox_grouped_test.dart @@ -420,6 +420,5 @@ void main() { expect(controller.selectedItem, 1); await tester.pump(); expect(() => controller.deselectAll(), throwsA(isA())); - }); } diff --git a/test/custom_grouped_checkbox_test.dart b/test/custom_grouped_checkbox_test.dart index f5cc628..cac0f0a 100644 --- a/test/custom_grouped_checkbox_test.dart +++ b/test/custom_grouped_checkbox_test.dart @@ -28,11 +28,11 @@ void main() { ); await tester.pumpAndSettle(); - await tester.tap(find.byKey(Key("1")),warnIfMissed: false); + await tester.tap(find.byKey(Key("1")), warnIfMissed: false); await tester.pumpAndSettle(); expect(controller.selectedItem, 1); - await tester.tap(find.byKey(Key("2")),warnIfMissed: false); + await tester.tap(find.byKey(Key("2")), warnIfMissed: false); await tester.pump(); expect(controller.selectedItem, 2); }); @@ -59,10 +59,10 @@ void main() { ); await tester.pump(); - await tester.tap(find.byType(Text).at(4),warnIfMissed: false); + await tester.tap(find.byType(Text).at(4), warnIfMissed: false); await tester.pump(); expect(controller.selectedItem, [5]); - await tester.tap(find.byType(Text).at(5),warnIfMissed: false); + await tester.tap(find.byType(Text).at(5), warnIfMissed: false); await tester.pump(); expect(controller.selectedItem, [5, 6]); }); @@ -95,15 +95,15 @@ void main() { ); await tester.pump(); - await tester.tap(find.byType(Text).at(4),warnIfMissed: false); + await tester.tap(find.byType(Text).at(4), warnIfMissed: false); await tester.pump(); expect(controller.selectedItem, [User("name5")]); controller.disabledItems([User("name6")]); - await tester.tap(find.byType(Text).at(5),warnIfMissed: false); + await tester.tap(find.byType(Text).at(5), warnIfMissed: false); await tester.pump(); expect(controller.selectedItem, [User("name5")]); controller.enabledItems([User("name6")]); - await tester.tap(find.byType(Text).at(5),warnIfMissed: false); + await tester.tap(find.byType(Text).at(5), warnIfMissed: false); await tester.pump(); expect(controller.selectedItem, [User("name5"), User("name6")]); });