RadioButton with Listview.builder



我的listview生成器中有一个单选按钮,listview生成器构建卡,当调用第一个单选按钮时,它会从所有后续卡中更改。如何仅隔离所选卡的单选按钮选项?

Center(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: data != null ? data.length : 0,
itemBuilder: (BuildContext context, index) {
Map data = snapshot.data[index];
//alts.length = 0;
if (data['alts'] != null) {
alts = json.decode(data['alts']);
alts.forEach((element) {});
} else
return snapshot.data[index]['alts'] =
Column(children: <Widget>[
Container(
padding:
EdgeInsets.fromLTRB(10, 20, 10, 0),
child: Card(                                                                                    
child: Container(
padding:
EdgeInsets.only(
left: 0,
right: 25,
bottom: 15),
child: Row(
//  crossAxisAlignment:
//CrossAxisAlignment
//   .start,
mainAxisSize:
MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
children: [
Row(children: [
Radio(
value: null,
groupValue:
null,
onChanged:
null),
Text(
'Certo',
style:
TextStyle(
color: Colors
.black,
fontSize: 16,
),
)
]),

尝试在代码中添加以下小组件:

Row(children: [
Radio(
key: UniqueKey(),  // add this line
value: null,
groupValue: null,
onChanged: null
),

它为每个单选按钮提供一个唯一的键。

最新更新