随笔 - 210  文章 - 0 评论 - 0 阅读 - 61532
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

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 ? "男" : "女")],
              ),
            ],
          )
        ],
      ),
    );
  }
}
复制代码

 

posted on   鲤斌  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
点击右上角即可分享
微信分享提示