In my problem, I want to add a one radio button when I tap on Radio button, it can be selected but when I tap again on that Radio button not unselect in flutter.
Radio(
value: StringConstant.radioDesc,
groupValue: selectCheckBox,
onChanged: (value) {
setState(() {
if (selectCheckBox == value) {
selectCheckBox = null;
} else {
selectCheckBox = value;
}
});
},
)
2
Answers
Set
toggleable
totrue
If you want to unselect radio button after selection then you need to set
toggleable = true
, by default itsfalse
refer toggleable, learn more about Radio Buttontoggleable : Set to true if radio button is allowed to be returned to an indeterminate state by selecting it again when selected.
Refer below code: