RadioButton
仅设置为其中一个且未更改
Radio<int>(activeColor: Colors.orange,value: 0, groupValue: 1,onChanged:
HandleRadio)
,Radio<int>(activeColor: Colors.amber,value: 1, groupValue: 1, onChanged:
HandleRadio)
,Radio<int>(activeColor: Colors.blue, value: 2, groupValue: 1, onChanged:
HandleRadio)
//function
int RadioValue = 0;
void HandleRadio(int value){
setState(() {
RadioValue = value;
});
}
应将其设置为选定的电台
答案 0 :(得分:1)
那是因为您为groupValue
赋予了Radio
硬编码值
这是工作代码。
Radio<int>(
activeColor: Colors.orange,
value: 0,
groupValue: radioValue, // changed this
onChanged: handleRadio,
),
Radio<int>(
activeColor: Colors.amber,
value: 1,
groupValue: radioValue, // changed this
onChanged: handleRadio,
),
Radio<int>(
activeColor: Colors.blue,
value: 2,
groupValue: radioValue, // changed this
onChanged: handleRadio,
),
//function
int radioValue = 0;
void handleRadio(int value) {
setState(() {
radioValue = value;
});
}