Skip to content

Commit

Permalink
#53
Browse files Browse the repository at this point in the history
* update pubspec,changelog,readme
* format files
  • Loading branch information
liodali committed Jul 18, 2021
1 parent 19e7628 commit d44ec90
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
* make multiple selection
* dialogGroupedCheckbox
* list of groupedCheckbox
* select/deselect items pragrammatically

## Getting Started
<img src="https://github.com/liodali/checkbox_grouped/blob/master/exampleCheckbox.gif?raw=true" alt="checkboxGrouped examples"><br>
Expand All @@ -19,7 +20,7 @@
Add the following to your `pubspec.yaml` file:

dependencies:
checkbox_grouped: ^1.5.0
checkbox_grouped: ^1.6.0



Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.5.0"
version: "1.6.0"
clock:
dependency: transitive
description:
Expand Down
9 changes: 4 additions & 5 deletions lib/src/common/state_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ abstract class StateGroup<K, T extends StatefulWidget> extends State<T>
});
}



void selectValues(List<K> values) {
values.forEach((value) {
final key = values.indexOf(value);
Expand All @@ -230,14 +228,15 @@ abstract class StateGroup<K, T extends StatefulWidget> extends State<T>
.where((element) => !selectionsValue.value.contains(element))
.toList());
}

void deselectValues(List<K> 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));
}
}
2 changes: 2 additions & 0 deletions lib/src/controller/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ abstract class BaseController {
///
/// [itemsValues] : (List) values that will be disabled
void disabledItemsByValues(List<dynamic> itemsValues);

/// select one item in group ( singeSelection/multiple selection)
/// [value] : (dynamic) value of item that should selected
void select<K>(K value);

/// select all items in group
void selectAll();

Expand Down
8 changes: 4 additions & 4 deletions lib/src/controller/group_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion test/checkbox_grouped_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,5 @@ void main() {
expect(controller.selectedItem, 1);
await tester.pump();
expect(() => controller.deselectAll(), throwsA(isA<AssertionError>()));

});
}
14 changes: 7 additions & 7 deletions test/custom_grouped_checkbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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]);
});
Expand Down Expand Up @@ -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")]);
});
Expand Down

0 comments on commit d44ec90

Please sign in to comment.