I have been trying to figure out where my mistake is for days but still couldn't solve it. Absolute novice in Flutter and I building multiple choice quiz app. I have multiple choice question screen which imports the radiolisttile choices from radio_button.dart file shown below.
Everything works except I cannot unselect a button once it's selected. In other words if I click each button all of them are selected.
import "package:flutter/material.dart";
class RB extends StatefulWidget {
RB({this.choice, this.value});
final String choice;
final String value;
@override
_RBState createState() => _RBState();
}
class _RBState extends State<RB> {
bool dense=false;
String _selection = '';
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
elevation: 5.0,
child: RadioListTile(
title: Text(widget.choice, style: TextStyle(color: Colors.blue,),),
value: widget.choice,
groupValue: _selection,
dense: dense,
activeColor: Colors.green,
onChanged:( val) { setState(() { _selection = val; print(val);}); },
),
),
);
}
}
Here the question_screen snippet
Column(
children: <Widget>[
Container(child: RB(choice:'A',value:'All of above',)),
Container(child: RB(choice:'B',value:'None of the above'))