Skip to content

Commit 05d863f

Browse files
authored
Merge pull request #81 from Frezyx/dev
Release version 5.0.0
2 parents a6d6cec + 8826590 commit 05d863f

File tree

26 files changed

+366
-474
lines changed

26 files changed

+366
-474
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 5.0.0
2+
- **MAIN FEAT**: GroupButton\<T> now is generic class.<br>
3+
Now you can create int, DateTime, double or YourCustomClass typed buttons List for default GroupButton constructor.<br> **More** [here](https://github.com/Frezyx/group_button/blob/master/example/lib/examples/generics_example/generics_example.dart)
4+
5+
- **BREAKING**: All deprecated by *4.3.0* and *4.6.0* fields was removed from package.<br>
6+
**More** [here](https://github.com/Frezyx/group_button#customize)
7+
8+
- **BREAKING**: buttonBuilder from *4.6.0* now build buttons by value <br>
9+
The buttonIndexedBuilder took over the past functionality of the buttonBuilder
10+
11+
- **INFO**: Updated examples & README
12+
113
## 4.8.0
214
- **FEAT**: Added enableIndexes abd disableIndexes methods for controller
315

README.md

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Follow these steps to use this package
4040

4141
```yaml
4242
dependencies:
43-
group_button: ^4.8.0 #latest version
43+
group_button: ^5.0.0
4444
```
4545
4646
### Add import package
@@ -56,30 +56,11 @@ Put this code in your project at an screen and learn how it works 😊
5656
```dart
5757
GroupButton(
5858
isRadio: false,
59-
spacing: 10,
6059
onSelected: (index, isSelected) => print('$index button is selected'),
6160
buttons: ["12:00", "13:00", "14:30", "18:00", "19:00", "21:40"],
6261
)
6362
```
6463

65-
### Can't easier to use
66-
Now you can use even simpler constructors to build your button groups. <br>
67-
Example for a group with a single value selection
68-
```dart
69-
GroupButton.radio(
70-
buttons: ['12:00', '13:00', '14:00'],
71-
onSelected: (i) => debugPrint('Button $i selected'),
72-
)
73-
```
74-
75-
Example for a group with a choice of multiple values
76-
```dart
77-
GroupButton.checkbox(
78-
buttons: ['12:00', '13:00', '14:00'],
79-
onSelected: (i, selected) => debugPrint('Button $i selected: $selected'),
80-
)
81-
```
82-
8364
### Controller
8465
**Starting from version 4.1.0** <br>
8566
You can control your Group Button using the controller
@@ -102,59 +83,66 @@ Column(
10283
),
10384
```
10485

86+
### Generic button value
87+
In new 5.0.0 version you can set custom buttons value type <br>
88+
It can be int, DateTime, double or YourCustomClass <br>
89+
Button text will be result of .toString() model method in common button display case <br>
90+
```dart
91+
GroupButton<DateTime>(
92+
buttons: [DateTime(2022, 4, 9), DateTime(2022, 4, 10)],
93+
)
94+
```
95+
96+
Also you can use generic button values with cutsom buttonBuilder <br>
97+
In order to turn values into any widget
98+
```dart
99+
GroupButton<DateTime>(
100+
buttons: [DateTime(2022, 4, 9), DateTime(2022, 4, 10)],
101+
buttonBuilder: (selected, date, context) {
102+
return Text('${date.year}-${date.month}-${date.day}');
103+
},
104+
),
105+
```
106+
105107
### Customize
106-
In order to customize your buttons inside *GroupButton* you can use code below</br>
107-
This code includes *all* the fields used in *GroupButton*
108+
In order to customize your buttons inside *GroupButton* you can use *GroupButtonOptions*
108109

109110
```dart
110-
GroupButton(
111-
controller: GroupButtonController(),
112-
spacing: 5,
113-
isRadio: false,
114-
groupingType: GroupingType.wrap,
115-
direction: Axis.horizontal,
116-
onSelected: (index, isSelected) => debugPrint(
117-
'$index button is ${isSelected ? 'selected' : 'unselected'}',
118-
),
119-
buttons: const [
120-
"Dart",
121-
"Kotlin",
122-
"Java",
123-
"Swift",
124-
"Objective-C",
125-
"Python",
126-
"JS",
127-
"C#",
128-
"C",
129-
"C++"
130-
],
131-
selectedButtons: const [1, 2, 3],
132-
selectedTextStyle: const TextStyle(
133-
fontWeight: FontWeight.w600,
134-
fontSize: 16,
135-
color: Colors.red,
111+
GroupButtonOptions(
112+
selectedShadow: const [],
113+
selectedTextStyle: TextStyle(
114+
fontSize: 20,
115+
color: Colors.pink[900],
136116
),
117+
selectedColor: Colors.pink[100],
118+
unselectedShadow: const [],
119+
unselectedColor: Colors.amber[100],
137120
unselectedTextStyle: TextStyle(
138-
fontWeight: FontWeight.w600,
139-
fontSize: 14,
140-
color: Colors.grey[600],
121+
fontSize: 20,
122+
color: Colors.amber[900],
141123
),
142-
selectedColor: Colors.white,
143-
unselectedColor: Colors.grey[300],
144-
selectedBorderColor: Colors.red,
145-
unselectedBorderColor: Colors.grey[500],
146-
borderRadius: BorderRadius.circular(5.0),
147-
selectedShadow: const <BoxShadow>[BoxShadow(color: Colors.transparent)],
148-
unselectedShadow: const <BoxShadow>[BoxShadow(color: Colors.transparent)],
149-
buttonHeight: 30,
150-
buttonWidth: 115,
151-
enableDeselect: false,
152-
maxSelected: 5
153-
);
124+
selectedBorderColor: Colors.pink[900],
125+
unselectedBorderColor: Colors.amber[900],
126+
borderRadius: BorderRadius.circular(100),
127+
spacing: 10,
128+
runSpacing: 10,
129+
groupingType: GroupingType.wrap,
130+
direction: Axis.horizontal,
131+
buttonHeight: 60,
132+
buttonWidth: 60,
133+
mainGroupAlignment: MainGroupAlignment.start,
134+
crossGroupAlignment: CrossGroupAlignment.start,
135+
groupRunAlignment: GroupRunAlignment.start,
136+
textAlign: TextAlign.center,
137+
textPadding: EdgeInsets.zero,
138+
alignment: Alignment.center,
139+
elevation: 0,
140+
),
154141
```
155142

156-
### Examples
143+
![](https://github.com/Frezyx/group_button/blob/master/example/rep_files/options_example.png?raw=true)
157144

145+
### Examples
158146
You can check more examples of using this package [here](example/lib)
159147

160148
<br>

example/lib/examples/button_builder_example/example.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class _ButtonBuilderExampleState extends State<ButtonBuilderExample> {
6060
shadowColor: Colors.grey[100]?.withOpacity(0.1),
6161
backgroundColor: Colors.white,
6262
title: Text(
63-
'GroupButton 4.8.0',
63+
'GroupButton 5.0.0',
6464
style: Theme.of(context).textTheme.headline6,
6565
),
6666
),
@@ -80,7 +80,7 @@ class _ButtonBuilderExampleState extends State<ButtonBuilderExample> {
8080
groupingType: GroupingType.column,
8181
),
8282
buttons: _checkboxButtons,
83-
buttonBuilder: (selected, index, context) {
83+
buttonIndexedBuilder: (selected, index, context) {
8484
return CheckBoxTile(
8585
title: _checkboxButtons[index],
8686
selected: selected,
@@ -93,7 +93,8 @@ class _ButtonBuilderExampleState extends State<ButtonBuilderExample> {
9393
},
9494
);
9595
},
96-
onSelected: (i, selected) => debugPrint('Button #$i $selected'),
96+
onSelected: (val, i, selected) =>
97+
debugPrint('Button: $val index: $i $selected'),
9798
),
9899
const SizedBox(height: 10),
99100
Padding(
@@ -108,7 +109,7 @@ class _ButtonBuilderExampleState extends State<ButtonBuilderExample> {
108109
isRadio: true,
109110
options: GroupButtonOptions(groupingType: GroupingType.column),
110111
buttons: _radioButtons,
111-
buttonBuilder: (selected, index, context) {
112+
buttonIndexedBuilder: (selected, index, context) {
112113
return RadioTile(
113114
title: _radioButtons[index],
114115
selected: _radioController.selectedIndex,
@@ -118,7 +119,8 @@ class _ButtonBuilderExampleState extends State<ButtonBuilderExample> {
118119
},
119120
);
120121
},
121-
onSelected: (i, selected) => debugPrint('Button #$i $selected'),
122+
onSelected: (val, i, selected) =>
123+
debugPrint('Button: $val index: $i $selected'),
122124
),
123125
],
124126
),

example/lib/examples/customizable_example/customizable_example.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CustomizableExample extends StatelessWidget {
2323
shadowColor: Colors.grey[100]?.withOpacity(0.1),
2424
backgroundColor: Colors.white,
2525
title: Text(
26-
'GroupButton 4.8.0',
26+
'GroupButton 5.0.0',
2727
style: Theme.of(context).textTheme.headline6,
2828
),
2929
),
@@ -34,7 +34,8 @@ class CustomizableExample extends StatelessWidget {
3434
buttons: customizableController.buttons
3535
.map((i) => '${i + 1}')
3636
.toList(),
37-
onSelected: (i, selected) => debugPrint('Button #$i $selected'),
37+
onSelected: (val, i, selected) =>
38+
debugPrint('Button: $val index: $i $selected'),
3839
),
3940
),
4041
bottomNavigationBar: GroupButtonBottomPanel(

example/lib/examples/extended_example/checkbox_example_part.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ Widget _buildCheckboxExample(GroupingType groupingType, {Axis? direction}) {
2323
),
2424
borderRadius: BorderRadius.circular(30),
2525
),
26-
onSelected: (index, isSelected) => debugPrint(
27-
'$index button is ${isSelected ? 'selected' : 'unselected'}',
28-
),
26+
onSelected: (val, i, selected) =>
27+
debugPrint('Button: $val index: $i $selected'),
2928
buttons: const [
3029
'Burger',
3130
'Sandwiches',

example/lib/examples/extended_example/example.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class _ExampleState extends State<_Example> {
4646
shadowColor: Colors.grey[100]?.withOpacity(0.1),
4747
backgroundColor: Colors.white,
4848
title: Text(
49-
'GroupButton 4.8.0',
49+
'GroupButton 5.0.0',
5050
style: Theme.of(context).textTheme.headline6,
5151
),
5252
),
@@ -70,7 +70,7 @@ class _ExampleState extends State<_Example> {
7070
groupingType: GroupingType.row,
7171
),
7272
buttons: const ['Wrap', 'Column', 'Row'],
73-
onSelected: (i, selected) {
73+
onSelected: (val, i, selected) {
7474
_extendedExampleController.selectedGroupingType = i;
7575
},
7676
),
@@ -86,7 +86,7 @@ class _ExampleState extends State<_Example> {
8686
spacing: 7.5,
8787
),
8888
buttons: const ['Radio', 'CheckBox'],
89-
onSelected: (i, selected) {
89+
onSelected: (_, i, selected) {
9090
_pageController.animateToPage(
9191
i,
9292
duration: const Duration(milliseconds: 200),

example/lib/examples/extended_example/radio_example_part.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Widget _buildRadioExample(GroupingType groupingType, {Axis? direction}) {
1515
direction: direction,
1616
groupingType: groupingType,
1717
),
18-
onSelected: (index, isSelected) =>
19-
debugPrint('$index button is selected'),
18+
onSelected: (val, i, selected) =>
19+
debugPrint('Button: $val index: $i $selected'),
2020
buttons: const ['12:00', '13:00', '14:30', '18:00', '19:00', '21:40'],
2121
),
2222
),
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:group_button/group_button.dart';
3+
4+
class FullOptionsSelectedExample extends StatelessWidget {
5+
const FullOptionsSelectedExample({Key? key}) : super(key: key);
6+
7+
@override
8+
Widget build(BuildContext context) {
9+
return MaterialApp(
10+
debugShowCheckedModeBanner: false,
11+
home: Scaffold(
12+
body: Center(
13+
child: GroupButton(
14+
buttons: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
15+
options: GroupButtonOptions(
16+
selectedShadow: const [],
17+
selectedTextStyle: TextStyle(
18+
fontSize: 20,
19+
color: Colors.pink[900],
20+
),
21+
selectedColor: Colors.pink[100],
22+
unselectedShadow: const [],
23+
unselectedColor: Colors.amber[100],
24+
unselectedTextStyle: TextStyle(
25+
fontSize: 20,
26+
color: Colors.amber[900],
27+
),
28+
selectedBorderColor: Colors.pink[900],
29+
unselectedBorderColor: Colors.amber[900],
30+
borderRadius: BorderRadius.circular(100),
31+
spacing: 10,
32+
runSpacing: 10,
33+
groupingType: GroupingType.wrap,
34+
direction: Axis.horizontal,
35+
buttonHeight: 60,
36+
buttonWidth: 60,
37+
mainGroupAlignment: MainGroupAlignment.start,
38+
crossGroupAlignment: CrossGroupAlignment.start,
39+
groupRunAlignment: GroupRunAlignment.start,
40+
textAlign: TextAlign.center,
41+
textPadding: EdgeInsets.zero,
42+
alignment: Alignment.center,
43+
elevation: 0,
44+
),
45+
isRadio: false,
46+
),
47+
),
48+
),
49+
);
50+
}
51+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:group_button/group_button.dart';
3+
4+
class GenericsExample extends StatelessWidget {
5+
GenericsExample({Key? key}) : super(key: key);
6+
7+
final controller = GroupButtonController(
8+
selectedIndex: 0,
9+
onDisablePressed: (i) => print('Button #$i is disabled'),
10+
);
11+
12+
final day = DateTime(2022, 4, 9);
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return MaterialApp(
17+
debugShowCheckedModeBanner: false,
18+
home: Scaffold(
19+
body: Center(
20+
child: GroupButton<DateTime>(
21+
controller: controller,
22+
buttons: List.generate(18, (i) => day.add(Duration(days: i))),
23+
onSelected: (date, i, selected) =>
24+
debugPrint('Button: $date index: $i selected: $selected'),
25+
buttonBuilder: (selected, date, context) {
26+
return Card(
27+
color: selected ? Colors.amber[900] : Colors.white,
28+
child: Padding(
29+
padding: const EdgeInsets.all(8.0),
30+
child: Text(
31+
'${date.year}-${date.month}-${date.day}',
32+
style: TextStyle(
33+
color: selected ? Colors.white : Colors.black,
34+
),
35+
),
36+
),
37+
);
38+
},
39+
),
40+
),
41+
),
42+
);
43+
}
44+
}

example/lib/examples/provider_example/ui/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class HomePageState extends State<HomePage>
9090
selectedColor: primaryColor,
9191
),
9292
isRadio: false,
93-
onSelected: (index, isSelected) {
93+
onSelected: (_, index, isSelected) {
9494
debugPrint(
9595
'$index button is ${isSelected ? 'selected' : 'unselected'}',
9696
);

0 commit comments

Comments
 (0)