账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    flutter使用radioListTile,出现点击item触发onchaged事件,但选中状态没有改变,这是为什么?
    52
    0

    flutter使用单选框。

    我使用了List<string> = ['item1','item2','item3'],用foreach方式去初始化radioListTile,出现点击item触发onchaged事件,但选中状态没有改变,这是为什么???

    widget.options 是一个List [“item1”, "item2", “item3”]

     String groupValue; // 整个单选组值, groupValue == value则选中
     List<Widget>optionChildren = new List<Widget>();
    void initState() {
        super.initState();
          groupValue = widget.options[0]; // 默认选中第一个
          
          widget.options.forEach(
            (item) {
              print(item);
              Widget itemWidget = new RadioListTile<String>(
                  value: item,
                  activeColor: Colors.red,
                  title: Text(item),
                  groupValue: groupValue,
                  onChanged: (val){
                    print("change${val} ${groupValue}");
                    setState(() {
                      groupValue = val;
                      print("change${val} ${groupValue}");
                    });
                  },
                );
              optionChildren.add(itemWidget);
            }
          );
      }
    
      Widget build(BuildContext context) {
        return new Column(
            children: optionChildren
          );
      }

    尝试过直接手动添加radioListTile选中状态是会改变的,目前问题现在的选项内容是不固定的,从服务端获取,请问该怎么办???没辙了

    @override
      Widget build(BuildContext context) {
        return new Column(
            children: <Widget>[
              new RadioListTile<String>(
                  value: "苹果",
                  activeColor: Colors.red,
                  title: Text("苹果"),
                  groupValue: groupValue,
                  onChanged: (val){
                    print("change${val} ${groupValue}");
                    setState(() {
                      groupValue = val;
                      print("change${val} ${groupValue}");
                    });
                  },
                ),
                new RadioListTile<String>(
                  value: "香蕉",
                  activeColor: Colors.red,
                  title: Text("苹果"),
                  groupValue: groupValue,
                  onChanged: (val){
                    print("change${val} ${groupValue}");
                    setState(() {
                      groupValue = val;
                      print("change${val} ${groupValue}");
                    });
                  },
                )
            ],
          );
      }
    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 遇海棠 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部