Skip to content

Commit

Permalink
Implement buttonIndexedTextBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Frezyx committed May 18, 2023
1 parent 59fd8f2 commit 8b3a5f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 5 additions & 4 deletions example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down Expand Up @@ -235,6 +235,7 @@
/* Begin PBXShellScriptBuildPhase section */
3399D490228B24CF009A79C7 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -344,7 +345,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -423,7 +424,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -470,7 +471,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
9 changes: 9 additions & 0 deletions lib/src/group_button_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GroupButton<T> extends StatelessWidget {
this.isRadio = true,
this.buttonIndexedBuilder,
this.buttonBuilder,
this.buttonIndexedTextBuilder,
this.enableDeselect = false,
this.maxSelected,
@Deprecated(
Expand Down Expand Up @@ -81,6 +82,13 @@ class GroupButton<T> extends StatelessWidget {
/// Your own custom buttons by button [T] value
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.
///
/// If you do not set up [buttonIndexedBuilder] and [buttonBuilder],
/// the text will be displayed on top of the button.
final GroupButtonIndexedTextBuilder? buttonIndexedTextBuilder;

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

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

final List<T> buttons;
Expand Down Expand Up @@ -72,6 +73,7 @@ class GroupButtonBody<T> extends StatefulWidget {
final GroupButtonController? controller;
final GroupButtonIndexedBuilder? buttonIndexedBuilder;
final GroupButtonValueBuilder<T>? buttonBuilder;
final GroupButtonIndexedTextBuilder? buttonIndexedTextBuilder;

@override
State<GroupButtonBody<T>> createState() => _GroupButtonBodyState<T>();
Expand Down Expand Up @@ -162,7 +164,9 @@ class _GroupButtonBodyState<T> extends State<GroupButtonBody<T>> {
);
} else {
button = GroupButtonItem(
text: widget.buttons[i].toString(),
text: widget.buttonIndexedTextBuilder
?.call(_isSelected(i), i, context) ??
widget.buttons[i].toString(),
onPressed: _controller.disabledIndexes.contains(i)
? () => _controller.onDisablePressed?.call(i)
: () {
Expand Down

0 comments on commit 8b3a5f1

Please sign in to comment.