Radio单选按钮组
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: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text("男:"), Radio( value: 1, onChanged: _radioChange, groupValue: sex, ), const SizedBox(width: 20), const Text("女:"), Radio( value: 2, onChanged: _radioChange, groupValue: sex, ) ], ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [Text("$sex"), Text(sex == 1 ? "男" : "女")], ), ], ), ); } }
标签:const,Text,value,sex,Radio,按钮,单选 From: https://www.cnblogs.com/xbinbin/p/17975407