Skip to content

Commit

Permalink
Implement buttonValueTextBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Frezyx committed May 18, 2023
1 parent 55e81e7 commit 2f00f9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/group_button_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GroupButton<T> extends StatelessWidget {
this.buttonIndexedBuilder,
this.buttonBuilder,
this.buttonIndexedTextBuilder,
this.buttonValueTextBuilder,
this.enableDeselect = false,
this.maxSelected,
@Deprecated(
Expand Down Expand Up @@ -83,12 +84,19 @@ class GroupButton<T> extends StatelessWidget {
final GroupButtonValueBuilder<T>? buttonBuilder;

/// This is a custom builder method that
/// allows you to set your own custom text for buttons based on their index.
/// allows you to set your own custom text for buttons based on their [index].
///
/// If you do not set up [buttonIndexedBuilder] and [buttonBuilder],
/// the text will be displayed on top of the button.
final GroupButtonIndexedTextBuilder? buttonIndexedTextBuilder;

/// This is a custom builder method that
/// allows you to set your own custom text for buttons based on their [value].
///
/// If you do not set up [buttonIndexedBuilder] and [buttonBuilder],
/// the text will be displayed on top of the button.
final GroupButtonValueTextBuilder<T>? buttonValueTextBuilder;

@override
Widget build(BuildContext context) {
return GroupButtonBody<T>(
Expand All @@ -100,6 +108,7 @@ class GroupButton<T> extends StatelessWidget {
buttonIndexedBuilder: buttonIndexedBuilder,
buttonBuilder: buttonBuilder,
buttonIndexedTextBuilder: buttonIndexedTextBuilder,
buttonValueTextBuilder: buttonValueTextBuilder,
enableDeselect: enableDeselect,
maxSelected: maxSelected,

Expand Down
4 changes: 4 additions & 0 deletions lib/src/group_button_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class GroupButtonBody<T> extends StatefulWidget {
this.buttonIndexedBuilder,
this.buttonBuilder,
this.buttonIndexedTextBuilder,
this.buttonValueTextBuilder,
}) : super(key: key);

final List<T> buttons;
Expand Down Expand Up @@ -74,6 +75,7 @@ class GroupButtonBody<T> extends StatefulWidget {
final GroupButtonIndexedBuilder? buttonIndexedBuilder;
final GroupButtonValueBuilder<T>? buttonBuilder;
final GroupButtonIndexedTextBuilder? buttonIndexedTextBuilder;
final GroupButtonValueTextBuilder<T>? buttonValueTextBuilder;

@override
State<GroupButtonBody<T>> createState() => _GroupButtonBodyState<T>();
Expand Down Expand Up @@ -166,6 +168,8 @@ class _GroupButtonBodyState<T> extends State<GroupButtonBody<T>> {
button = GroupButtonItem(
text: widget.buttonIndexedTextBuilder
?.call(_isSelected(i), i, context) ??
widget.buttonValueTextBuilder
?.call(_isSelected(i), widget.buttons[i], context) ??
widget.buttons[i].toString(),
onPressed: _controller.disabledIndexes.contains(i)
? () => _controller.onDisablePressed?.call(i)
Expand Down

0 comments on commit 2f00f9c

Please sign in to comment.