'How can I implement selecting only one button from group buttons in flutter
I have added a picture of what I plan to implement. It's a group button where you can only select one option at a time. I used a package called "group_button" but it allows multiple selection at a time which isn't what I want.
Recommend an alternative means of achieving this.
Solution 1:[1]
Updated 18.02.2022
They removed old constructor GroupButton.radio and GroupButton.checkbox in version 4.4.0 and still don't updated documentation.
Proper solution is set isRadio property of GroupButton to true.
GroupButton(
isRadio: true,
onSelected: (index, isSelected) => print('$index button is selected'),
buttons: ["12:00", "13:00", "14:30", "18:00", "19:00", "21:40"],
)
Old answer:
Never used that package but by looking on they pub.dev page I can see following.
Now you can use even simpler constructors to build your button groups. Example for a group with a single value selection:
GroupButton.radio(
buttons: ['12:00', '13:00', '14:00'],
onSelected: (i) => debugPrint('Button $i selected'),
)
Link: https://pub.dev/packages/group_button#cant-easier-to-use
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
