I would like to execute some code when I press on Radio. GestureDetector works everywhere, but not here. If you run the code bellow, you get response (print) when tapping on Text, but not when tapping on Radio (both are wrapped in same GestureDetector).
Do you have any suggestions, how to overcome this (or explanation why this happens)?
class _MyHomePageState extends State<MyHomePage> {
int radioGroupValue = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: GestureDetector(
onTap: () => print("GestureDetector has been tapped."),
child: new Row(children: [
new Radio(
value: 0,
groupValue: radioGroupValue,
onChanged: _handleRadioValueWkotType,
),
new Text("label 1"),
new Radio(
value: 1,
groupValue: radioGroupValue,
onChanged: _handleRadioValueWkotType,
),
new Text("label 2"),
])),
));
}
void _handleRadioValueWkotType(int value) {
setState(() {
radioGroupValue = value;
});
}
}
You can use
RadioListTile
widget which acts same as theradio
widget, but it has extratitle
parameter where you can providetext
which will be shown just beside theradio
widget and also clicking on the title text will behaves same as clicking on radio widget itself.Check out official link and example