I need to create a group of radio buttons without using the stateful widget. I want a BLoC Pattern in flutter to create a group of radio buttons. How to create it?
I have only tried using the regular Radio widget using the onChange state management.
I need to create a group of radio buttons without using the stateful widget. I want a BLoC Pattern in flutter to create a group of radio buttons. How to create it?
I have only tried using the regular Radio widget using the onChange state management.
Copyright © 2021 Jogjafile Inc.
Please try to post some code in the future, so we can help you figure out what is wrong with the code itself or the approach. I'm not sure if this is precisely what you are asking for, but you can create stateless widget, which will act as radio buttons group using BLOC library.
Let's say you have 2 options (for radio buttons):
and to simplify things, we will create simplest Cubit possible, to manipulate state of radio buttons group:
To make it work in the stateless widget, you need to create the cubit and whenever the
onChangedfunction is invoked, just pass the result to the cubit. UsingBlocBuilderwill automatically update the UI:I hope it helps.