RadioListTile单选按钮组
class RadioPage extends StatefulWidget { const RadioPage({super.key}); @override State<RadioPage> createState() => _RadioPageState(); } class _RadioPageState extends State<RadioPage> { int sex = 1; _radioChange(value) { setState(() { sex = value; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Radio"), ), body: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const SizedBox(width: 20), const Divider(), Column( children: [ RadioListTile( title: Text("男"), value: 1, groupValue: sex, onChanged: _radioChange), RadioListTile( title: Text("女"), value: 2, groupValue: sex, onChanged: _radioChange), Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[Text("$sex"), Text(sex == 1 ? "男" : "女")], ), ], ) ], ), ); } }
标签:const,Text,value,sex,单选,按钮,RadioListTile From: https://www.cnblogs.com/xbinbin/p/17999811