flutter中radio单选使用

在一个数组容器里放置两个及其以上radio,当radio的group value和自己value相等时,便是选中状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int groupValue = 1;
_onChange(value){
if(mounted)
setState(() {
groupValue = value;
});
}

Row(

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Radio(
value: 1,
groupValue: groupValue,
onChanged: (T) => _onChange(T),
),
Radio(
value: 2,
groupValue: groupValue,
onChanged: (T) => _onChange(T),
),
Radio(
value: 3,
groupValue: groupValue,
onChanged: (T) => _onChange(T),
),
],
)

参考:https://blog.csdn.net/zhangwes/article/details/104978660