-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deselect stops working when controller is added #89
Comments
Hi @divan! Cool nickname 😄 |
From you description I understand that your situation similar to my when I create TalkerScreenFilter in my another package |
Okay, I started testing example code, and it worked. so I figure out that it was my mistake – I put While we here, quick question – is there any way to preselect buttons without controller? It would be really handy to use GroupButton from stateless controllers and be able to init with parameter. So in my code the class looks like this: class MyField extends StatelessWidget {
MyField({Key? key}) : super(key: key);
final ctrl = GroupButtonController();
@override
Widget build(BuildContext context) {
return FormBuilderField(
builder: (FormFieldState<dynamic> field) {
return GroupButton(
onSelected: (index, isSelected, _) =>
print('$index button is selected'),
buttons: ["12:00", "13:00", "14:30", "18:00", "19:00", "21:40"],
buttonBuilder: null,
enableDeselect: true,
controller: ctrl,
);
},
);
}
}
Now, the challenge is how to use that I probably need to explore more how to properly init fields in this form builder, but I think having something like |
Still puzzled how to init values in this use case.. So my initial code (the one that broken deselect feature) was: class MyField extends StatelessWidget {
MyField({Key? key}) : super(key: key);
final ctrl = GroupButtonController();
final items = ["12:00", "13:00", "14:30", "18:00", "19:00", "21:40"];
@override
Widget build(BuildContext context) {
return FormBuilderField(
builder: (FormFieldState<dynamic> field) {
if (field.value != null) ctrl.selectIndex(items.indexOf(field.value)); // <-- this breaks deselecting, but otherwise works as intended
return GroupButton(
onSelected: (index, isSelected, _) =>
print('$index button is selected'),
buttons: items,
buttonBuilder: null,
enableDeselect: true,
controller: ctrl,
);
},
);
}
}
|
You can make MyField StatefulWidget if (field.value != null) ctrl.selectIndex(items.indexOf(field.value)); |
Didn't notice Formbuilder 🤣 |
You can raise FormBuilder to a higher level FormBuilder -> |
Hmm, not sure I got how to do this. @Frezyx don't want to steal your time here. so the last question – did the GroupButton API has a |
Hi, thanks for a great plugin.
I use it in a custom FormBuilderField, and needed a way to initialize selected buttons. It wasn't obvious how to set init values, but eventually I made it by adding GroupButtonController. All worked well until I discovered that deselecting buttons stopped working.
If I remove controller, deselecting works again (but no way to set init values).
Any hints on what can be wrong? Is it a bug or I'm doing something wrong? (maybe there is a way to preselect buttons without controller?)
The text was updated successfully, but these errors were encountered: