So I try to use Radio button to choose some option inside Alert dialog. It looks like this: .
The radio button remains inactive when I click on it. But when I close the alert dialog and open it again, the radio button is activated. For example, I chose the second option, but the radio button still shows the first option is active. But if I select the second option, then tap elsewhere to close the alert dialog, when I open it again I find that the second option is enabled
My code look like this:
AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: blackColor,
width: 3,
),
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
on_progress,
Radio(
value: 1,
groupValue: _StatusVal,
onChanged: (int? value) {
setState(() {
_StatusVal=value!;
print(_StatusVal);
(_StatusVal==1)?progress=true:progress=false;
});
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
selesai,
Radio(
value: 2,
groupValue: _StatusVal,
onChanged: (int? value) {
setState(() {
_StatusVal=value!;
print(_StatusVal);
(_StatusVal==1)?progress=true:progress=false;
});
},
),
],
),
],
),
),
I have two item inside my alert dialog. It seems that the radio button doesn't updated because i put it inside my alert dialog. How to activate the button inside the alert dialog?
CodePudding user response:
Try to add your AlertDialog
inside StatefulBuilder
hope its help to you.
StatefulBuilder(
builder: (context, StateSetter setState) {
return AlertDialog();
}
);
CodePudding user response:
This is because you initialize "_StatusVal=1" and then try this code Radio( value: 2, groupValue: _StatusVal, onChanged: (int? value) { setState(() { _StatusVal=value!; print(_StatusVal); (_StatusVal==1)?progress=false:progress=true; });
},
),