diff --git a/CHANGELOG.md b/CHANGELOG.md index a180b72..5fb0c3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.7.0] - add new widget ListCustomGroupedCheckbox +* * create ListCustomGroupedCheckbox to manage multiple custom grouped in list +* * create ListCustomController to get selected item +* * remove deprecated attributes ## [1.6.1+1] - fix readme ## [1.6.1] - fix bug [#55] * add new attribute `isScrollable` to make widget scrollable or not (default:true) diff --git a/README.md b/README.md index 6af0d15..8af5be8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # checkbox_grouped -![pub](https://img.shields.io/badge/pub-v1.6.1%2B1-blue) ![GitHub](https://img.shields.io/github/license/liodali/checkbox_grouped) +![pub](https://img.shields.io/badge/pub-v1.7.0-orange) ![GitHub](https://img.shields.io/github/license/liodali/checkbox_grouped) * grouped (checkbox/radioButton) * customisable grouped checkbox @@ -20,7 +20,7 @@ Add the following to your `pubspec.yaml` file: dependencies: - checkbox_grouped: ^1.6.1+1 + checkbox_grouped: ^1.7.0 @@ -508,4 +508,154 @@ controller.disabledItemsByTitles(int indexGroup,List items) |`mapItemGroupedType` | (Map) define type of each group can be chips/switch/(checkbox or radio) | ------------------ + +##ListCustomGroupedCheckbox +> display list of groupedCheckbox +> return all values selected +> +### Declare ListGroupController to get all item selected or get item selected by group index + +```dart +ListGroupController controller = ListGroupController(); +``` + +#### `ListCustomGroupController` +| Properties | Description | +|------------------------------ |--------------| +|`isMultipleSelectionPerGroup` | (List) enable multiple selection in each grouped checkbox. | +|`initSelectedValuesByGroup` | (List) A Initialize list of values on each group of checkbox that will be selected in group. | + + +### Get current selection +* get all selection +1) list +```dart +final selectedItems = controller.allSelectedItems; +``` +2) map +```dart +final selectedItems = controller.mapSelectedItems; +``` +* get all selection by group + +```dart +final selectedItems = controller.selectedItemsByGroupIndex(indexGroup); +``` + +#### `ListCustomGroupedCheckbox` +| Properties | Description | +|-------------------------------------|--------------------------------------------------------------------------------------------------| +|`controller` | (required) manage the ListGroupedCheckbox. | +|`children` | (required) list of CustomIndexedWidgetBuilder to return widget of items for each group,should be non null widgets | +|`groupTitles` | A list of String for group checkbox in each CustomGrouped. | +|`groupTitlesWidget` | A list of list of widgets that describes custom Title for each group. | +|`listValuesByGroup` | (required) Values contains in each element in each CustomGroupedCheckbox. | +|`isScrollable` | (bool) make the parent widget scrollable or disable it (default:true). | +|`onSelectedGroupChanged` | CallBack to get all selected items when one of item hit it make select new items or deselect items | +|`titleGroupedAlignment` | (Alignment) align text title of each group | +|`titleGroupedTextStyle` | (TextStyle) style text for title of each group | + + +### basic example +```dart +final controller = +ListCustomGroupController(isMultipleSelectionPerGroup: [true, false]); +final data = [ + List<_User>.generate( + 10, + (i) => _User( + name: faker.person.name(), + email: faker.internet.email(), + ), + ), + List.generate( + 10, + (i) => faker.person.name(), + ) +] +ListCustomGroupedCheckbox( + controller: controller, + onSelectedGroupChanged: (values) { + print(values); + }, + isScrollable: true, + titleGroupedAlignment: Alignment.centerLeft, + groupTitles: ["Users", "Names"], + children: [ + CustomIndexedWidgetBuilder( + itemBuilder: (ctx, index, selected, isDisabled) { + return Card( + margin: EdgeInsets.only( + top: 5.0, + bottom: 5.0, + ), + child: ListTile( + tileColor: selected ? Colors.green[300] : Colors.white, + title: Text( + (data[0][index] as _User).name, + ), + subtitle: Text( + (data[0][index] as _User).email, + ), + trailing: Opacity( + opacity: selected ? 1 : 0, + child: Icon( + Icons.check, + color: Colors.white, + size: 24, + ), + ), + ), + ); + }), + CustomGridIndexedWidgetBuilder( + itemBuilder: (ctx, index, selected, isDisabled) { + return Card( + color: selected ? Colors.green[300] : Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + 12.0, + ), + ), + margin: EdgeInsets.only( + top: 5.0, + bottom: 5.0, + ), + child: Stack( + children: [ + Center( + child: Text( + data[1][index], + maxLines: 3, + overflow: TextOverflow.fade, + ), + ), + Positioned( + top: 5, + right: 8, + child: Opacity( + opacity: selected ? 1 : 0, + child: Icon( + Icons.check, + color: Colors.white, + size: 24, + ), + ), + ), + ], + ), + ); + }, + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 3, + crossAxisSpacing: 5.0, + ) + ), + ], + listValuesByGroup: data, + ) + + +``` + MIT Licences \ No newline at end of file diff --git a/example/lib/list_of_grouped.dart b/example/lib/list_of_grouped.dart index 9f3b870..82fdeab 100644 --- a/example/lib/list_of_grouped.dart +++ b/example/lib/list_of_grouped.dart @@ -42,12 +42,12 @@ class _ListOfGroupedState extends State { groupTitles: List.generate(5, (index) => "groupe $index"), values: List.generate( 5, - (i) => List.generate( - 5, (j) => "${(i + Random().nextInt(100)) * j}"), + (i) => + List.generate(5, (j) => "${(i + Random().nextInt(100)) * j}"), ), titles: List.generate( 5, - (i) => List.generate(5, (j) => "Title:$i-$j"), + (i) => List.generate(5, (j) => "Title:$i-$j"), ), mapItemGroupedType: { 1: GroupedType.Chips, diff --git a/example/pubspec.lock b/example/pubspec.lock index f602897..6ee14c6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -42,7 +42,7 @@ packages: path: ".." relative: true source: path - version: "1.6.1+1" + version: "1.7.0" clock: dependency: transitive description: diff --git a/lib/checkbox_grouped.dart b/lib/checkbox_grouped.dart index 4d5ec08..e82d321 100644 --- a/lib/checkbox_grouped.dart +++ b/lib/checkbox_grouped.dart @@ -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,ItemWidget; + 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' diff --git a/lib/src/common/utilities.dart b/lib/src/common/utilities.dart index 8d350f2..3527350 100644 --- a/lib/src/common/utilities.dart +++ b/lib/src/common/utilities.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; typedef CustomListener = void Function(dynamic); typedef OnGroupChanged = void Function(dynamic selected); -typedef OnCustomGroupChanged = void Function(Map selected); +typedef OnCustomGroupChanged = void Function(Map selected); /// Signature for a function that creates a widget for a given index,isChecked and disabled, e.g., in a /// list. diff --git a/lib/src/controller/list_custom_group_controller.dart b/lib/src/controller/list_custom_group_controller.dart index fa7f49e..566b3fb 100644 --- a/lib/src/controller/list_custom_group_controller.dart +++ b/lib/src/controller/list_custom_group_controller.dart @@ -2,8 +2,8 @@ import '../widgets/list_custom_grouped_checkbox.dart'; /// ListGroupController to manage list of grouped checkbox/chips/switch /// [isMultipleSelectionPerGroup] : (List) enable multiple selection in each grouped checkbox. -/// [initSelectedValues] : (List) A Initialize list of values on each group of checkbox that will be selected in group. - +/// +/// [initSelectedValuesByGroup] : (List) A Initialize list of values on each group of checkbox that will be selected in group. class ListCustomGroupController { final List isMultipleSelectionPerGroup; final Map> initSelectedValuesByGroup; diff --git a/lib/src/widgets/list_custom_grouped_checkbox.dart b/lib/src/widgets/list_custom_grouped_checkbox.dart index 92066fa..b2f188a 100644 --- a/lib/src/widgets/list_custom_grouped_checkbox.dart +++ b/lib/src/widgets/list_custom_grouped_checkbox.dart @@ -44,8 +44,7 @@ class ListCustomGroupedCheckbox extends StatefulWidget { this.titleGroupedAlignment = Alignment.centerLeft, this.onSelectedGroupChanged, Key? key, - }) : - //assert(controller.isMultipleSelectionPerGroup.isEmpty), + }) : assert(children.isNotEmpty), assert((groupTitles == null && (groupTitlesWidget != null && groupTitlesWidget.isNotEmpty)) || (groupTitlesWidget == null && diff --git a/lib/src/widgets/simple_grouped_chips.dart b/lib/src/widgets/simple_grouped_chips.dart index 2f738a2..1a95b1f 100644 --- a/lib/src/widgets/simple_grouped_chips.dart +++ b/lib/src/widgets/simple_grouped_chips.dart @@ -90,13 +90,10 @@ class SimpleGroupedChipsState extends StateGroup { super.initState(); groupStyle = ChipGroupStyle( backgroundColorItem: widget.chipGroupStyle.backgroundColorItem, - selectedColorItem: - widget.chipGroupStyle.selectedColorItem , - textColor: widget.chipGroupStyle.textColor , - selectedTextColor: - widget.chipGroupStyle.selectedTextColor , - disabledColor: - widget.chipGroupStyle.disabledColor, + selectedColorItem: widget.chipGroupStyle.selectedColorItem, + textColor: widget.chipGroupStyle.textColor, + selectedTextColor: widget.chipGroupStyle.selectedTextColor, + disabledColor: widget.chipGroupStyle.disabledColor, selectedIcon: widget.chipGroupStyle.selectedIcon, itemTitleStyle: widget.chipGroupStyle.itemTitleStyle, ); diff --git a/lib/src/widgets/simple_grouped_switch.dart b/lib/src/widgets/simple_grouped_switch.dart index 66fbe98..658c336 100644 --- a/lib/src/widgets/simple_grouped_switch.dart +++ b/lib/src/widgets/simple_grouped_switch.dart @@ -116,11 +116,11 @@ class SimpleGroupedSwitchState extends StateGroup { indexItem: index, onItemChanged: changeSelection, item: item, - activeColor: widget.groupStyle?.activeColor , + activeColor: widget.groupStyle?.activeColor, textStyle: widget.groupStyle?.itemTitleStyle?.copyWith( - color: item.checked! - ? widget.groupStyle?.activeColor - : widget.groupStyle?.itemTitleStyle?.color) , + color: item.checked! + ? widget.groupStyle?.activeColor + : widget.groupStyle?.itemTitleStyle?.color), ); }, );