如果您想在单击 textview 时选择单选按钮值,那么您需要在单击 textview 时更改单选按钮的 groupValue
示例代码
class MyApp extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<MyApp> {
int _radioValue1 = 0;
void _handleRadioValueChange1(int value) {
setState(() {
_radioValue1 = value;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('RadioListTile Demo'),
),
//hit Ctrl+space in intellij to know what are the options you can use in flutter widgets
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.all(32.0),
child: Column(
children: <Widget>[
Radio(
value: 0,
groupValue: _radioValue1,
onChanged: _handleRadioValueChange1,
),
Radio(
value: 1,
groupValue: _radioValue1,
onChanged: _handleRadioValueChange1,
),
Radio(
value: 2,
groupValue: _radioValue1,
onChanged: _handleRadioValueChange1,
),
GestureDetector(
onTap: () {
setState(() {
_radioValue1 = 0;
});
},
child: Text("Select First Radio Button"),
),
GestureDetector(
onTap: () {
setState(() {
_radioValue1 = 1;
});
},
child: Text("Select Second Radio Button"),
),
GestureDetector(
onTap: () {
setState(() {
_radioValue1 = 2;
});
},
child: Text("Select Third Radio Button"),
)
],
),
),
),
);
}
}