I run radio button widgets in Streambuilder, but the selected option does not become active when the selection is made, why? I am facing this problem when I want to select by String value. What part am I doing wrong in this case? Ra Could you help?
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});
});
},
),
));
}
}
Declare your
String _value = '';
outside of your build function, as of right now every time you setState your _value will be set to an empty string instead of the value you want.