Enhancement thought for using with Bloc...
JulianSwales opened this issue · 2 comments
Hi, this is more an enhancement thought than an Issue.
I am using this package in an app that is using Bloc.. Specifically as a piece of a form using flutter_form_bloc.
I ran into an issue where if the state of the selection is changed by bloc, then the widget doesn't update.. In my use case, the form can be loaded from a web query, so the initial sate of the form might be updated externally by bloc.
To solve this for me I added the following to the _GroupButtonBodyState to allow for the widget to update..
@override
void didUpdateWidget(Widget OldWidget) {
for (var i = 0; i < widget.buttons.length; i++) {
if (widget.selectedButtons!.contains(i)) {
_selectedIndexes[i] = true;
} else {
_selectedIndexes[i] = false;
}
}
setState(() {});
}
I realize this doesn't cover the radio Button case, but I wasn't using that format for my use case.
I'm still learning Flutter so this may not be the best way to do this.
I'm not sure if this is an enhancement you may want to include in some form, I just thought I'd pass on my use case.
Thanks for the great package.
https://github.com/bookyo/group_button, i add GroupButtonController to this widget, you can use controller to get selectedIndex or selectedIndexes, and setSelectedIndex/setSelectedIndexes to set selectedIndex/selectedIndexes,
you can check example: https://github.com/bookyo/group_button/blob/master/example/lib/examples/styles_example/example.dart
you can use controller by GetX or Bloc or other state manager to controller widget show.
Now this available in new 4.0.0 version