Skip to content

Commit

Permalink
docs: add docs for readme,change changelog (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
liodali committed Oct 13, 2021
1 parent d6ecbc0 commit 70b5a40
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
154 changes: 152 additions & 2 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.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
Expand All @@ -20,7 +20,7 @@
Add the following to your `pubspec.yaml` file:

dependencies:
checkbox_grouped: ^1.6.1+1
checkbox_grouped: ^1.7.0



Expand Down Expand Up @@ -508,4 +508,154 @@ controller.disabledItemsByTitles(int indexGroup,List<String> 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<bool>) 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<String>.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
6 changes: 3 additions & 3 deletions example/lib/list_of_grouped.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class _ListOfGroupedState extends State<ListOfGrouped> {
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,
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.6.1+1"
version: "1.7.0"
clock:
dependency: transitive
description:
Expand Down
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,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'
Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
typedef CustomListener = void Function(dynamic);

typedef OnGroupChanged<T> = void Function(dynamic selected);
typedef OnCustomGroupChanged<T> = void Function(Map<int,dynamic> selected);
typedef OnCustomGroupChanged<T> = void Function(Map<int, dynamic> selected);

/// Signature for a function that creates a widget for a given index,isChecked and disabled, e.g., in a
/// list.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/controller/list_custom_group_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import '../widgets/list_custom_grouped_checkbox.dart';

/// ListGroupController to manage list of grouped checkbox/chips/switch
/// [isMultipleSelectionPerGroup] : (List<bool>) 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<bool> isMultipleSelectionPerGroup;
final Map<int, List<dynamic>> initSelectedValuesByGroup;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/widgets/list_custom_grouped_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
11 changes: 4 additions & 7 deletions lib/src/widgets/simple_grouped_chips.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ class SimpleGroupedChipsState<T> extends StateGroup<T, SimpleGroupedChips> {
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,
);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/widgets/simple_grouped_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class SimpleGroupedSwitchState<T> extends StateGroup<T, SimpleGroupedSwitch> {
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),
);
},
);
Expand Down

0 comments on commit 70b5a40

Please sign in to comment.