Skip to content

Commit

Permalink
feat : add new method to get data (#53)
Browse files Browse the repository at this point in the history
* add `allSelectedItemsGrouped` to get data grouped in list if item isMultipleSelection
* add byGroup attribut in  getAllValues
  • Loading branch information
liodali committed Oct 12, 2021
1 parent 6172225 commit 50f8a50
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/checkbox_grouped.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export 'src/controller/group_controller.dart';
export 'src/controller/list_group_controller.dart';
export 'src/controller/list_custom_group_controller.dart';
export 'src/widgets/custom_grouped_checkbox.dart'
hide CustomGroupedCheckboxState;
hide CustomGroupedCheckboxState,ItemWidget;
export 'src/widgets/list_grouped_checkbox.dart' hide ListGroupedCheckboxState;
export 'src/widgets/show_dialog_grouped_checkbox.dart';
export 'src/widgets/simple_grouped_checkbox.dart'
Expand Down
4 changes: 2 additions & 2 deletions lib/src/common/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ typedef OnCustomGroupChanged<T> = void Function(Map<int,dynamic> selected);
typedef CustomItemIndexedWidgetBuilder = Widget Function(
BuildContext builder,
int index,
bool? checked,
bool? isDisabled,
bool checked,
bool isDisabled,
);

enum GroupedType { Chips, Switch, Default }
Expand Down
5 changes: 4 additions & 1 deletion lib/src/controller/list_custom_group_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class ListCustomGroupController {
late ListCustomGroupedCheckboxState _state;

Future<List<dynamic>> get allSelectedItems async =>
await _state.getAllValues();
await _state.getAllValues(byGroup: false);

Future<List<dynamic>> get allSelectedItemsGrouped async =>
await _state.getAllValues(byGroup: true);

Future<Map<int, dynamic>> get mapSelectedItems async =>
await _state.getMapValues();
Expand Down
9 changes: 5 additions & 4 deletions lib/src/widgets/custom_grouped_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ class CustomGroupedCheckboxState<T>
return ValueListenableBuilder<CustomItem<T?>>(
valueListenable: items[index],
builder: (ctx, value, child) {
return _ItemWidget(
return ItemWidget(
child: widget.itemBuilder(
context,
index,
items[index].value.checked,
items[index].value.checked!,
items[index].value.isDisabled,
),
value: items[index].value.checked,
Expand Down Expand Up @@ -249,12 +249,13 @@ class CustomGroupedCheckboxState<T>
}
}

class _ItemWidget extends StatelessWidget {
@visibleForTesting
class ItemWidget extends StatelessWidget {
final Widget? child;
final Function(bool)? callback;
final bool? value;

_ItemWidget({
ItemWidget({
this.child,
this.callback,
this.value,
Expand Down
11 changes: 9 additions & 2 deletions lib/src/widgets/list_custom_grouped_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,16 @@ class ListCustomGroupedCheckboxState extends State<ListCustomGroupedCheckbox> {
super.dispose();
}

Future<List> getAllValues() async {
Future<List> getAllValues({bool byGroup = true}) async {
List resultList = List.empty(growable: true);
var values = listControllers.map((e) => e.selectedItem).where((v) {
var values = listControllers.map((e) {
switch (e.isMultipleSelection && byGroup) {
case true:
return [e.selectedItem];
default:
return e.selectedItem;
}
}).where((v) {
if (v != null) {
if (v is List && v.isNotEmpty) {
return true;
Expand Down

0 comments on commit 50f8a50

Please sign in to comment.