我在 Streambuilder 中运行单选按钮小部件,但在进行选择时所选选项没有变为活动状态,为什么?当我想按字符串值进行选择时,我遇到了这个问题。在这种情况下,我做错了什么?拉 你能帮忙吗?
StreamBuilder<QuerySnapshot>(
stream:...
builder: (context, snapshot) {
....
return buildBody(context, snapshot.data.docs);
}
},
)
Widget buildBody(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView(
padding: EdgeInsets.only(top: 20),
children:
snapshot.map<Widget>((e) => buildListItem(context, e)).toList());
}
Widget buildListItem(BuildContext context, DocumentSnapshot data) {
final row = Survey.fromSnapshot(data);
String _value = '';
return Padding(
padding: EdgeInsets.all(10),
key: ValueKey(row.name),
child: Container(
decoration:.....
child: ListTile(
title: .....
leading: Radio<String>(
activeColor: Colors.blueGrey,
groupValue: _value,
value: row.name,
onChanged: (value) {
setState(() {
_value = value;
});
},
),
onTap: () {
FirebaseFirestore.instance.runTransaction((transaction) async {
final freshSnapShot = await transaction.get(row.reference);
final fresh = Survey.fromSnapshot(freshSnapShot);
await transaction.update(
row.reference, {'isim': row.name, 'oy': row.vote + 1});
});
},
),
));
}
}