当无线电处于启用状态时值 == 组值在您的情况下,所有 8 个无线电都共享一个 groupValue,并且对于所有行,第一个的值为 0,第二个的值为 1。
然后,当您单击左侧单选按钮时,全局值设置为 0,然后所有左侧单选按钮(它们的值都为 0)启用,反之亦然。
要创建您想要做的事情,您应该为每个设置唯一的值Radio每个组都有独特的组值ROW
这是一个工作示例。
class Affiche_grille extends StatefulWidget {
@override
_QuestionWidgetState createState() => _QuestionWidgetState();
}
class _QuestionWidgetState extends State<Affiche_grille> {
List<RadioModel> sampleData = [];
List<int> groupValue = [];
List<List<int>> value = [];
@override
void initState() {
super.initState();
sampleData.add(new RadioModel(false, 'A', 'April 18', 'text1'));
sampleData.add(new RadioModel(false, 'B', 'April 17', 'text2'));
sampleData.add(new RadioModel(false, 'C', 'April 16', 'text3'));
sampleData.add(new RadioModel(false, 'D', 'April 15', 'text4'));
groupValue.add(0);
groupValue.add(2);
groupValue.add(4);
groupValue.add(6);
value.add([0,1]);
value.add([2,3]);
value.add([4,5]);
value.add([6,7]);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("ListItem"),
),
body: ListView.builder(
itemCount: sampleData.length,
itemBuilder: (context, index) => ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
Radio(
groupValue: groupValue[index],
value: value[index][0],
onChanged: (newValue) => setState(() => groupValue[index] = newValue),
),
Radio(
groupValue: groupValue[index],
value: value[index][1],
onChanged: (newValue) => setState(() => groupValue[index] = newValue),
),
],
),
),
);
}
}