Flutter中的AlertDialog小部件内的单选按钮小部件不起作用 [英] Radio Button widget not working inside AlertDialog Widget in Flutter

查看:96
本文介绍了Flutter中的AlertDialog小部件内的单选按钮小部件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户选择单选按钮"中提供的选项,然后再移至我的Flutter应用程序"中的第二页.我正在显示的Alertdialog中显示单选按钮小部件,但选择后单选按钮未更改.

I want user to select the option given in Radio Button before moving to second page in My Flutter Application. I'm showing Radio button widget inside Alertdialog it shows but radio button not changed after selecting.

所有国家/地区类别

floatingActionButton: FloatingActionButton(
      child: Icon(Icons.create),
      onPressed: () {
        return showDialog(
            context: context,
            builder: (context) => AlertDialog(
              title: Text("Select Grade System and No of Subjects"),
              actions: <Widget>[
                    Radio(value: 0, groupValue: groupValue, onChanged: selectRadio),
                    Radio(value: 1, groupValue: groupValue, onChanged: selectRadio),
                    ],
            ));
      },
    ),

selectRadio功能

selectRadio Function

void selectRadio(int value)
{
setState(() {
  groupValue=value;
});
}

推荐答案

正如我所说的,以上评论 showDialog创建了新的上下文,因此调用小部件上的setState不会影响对话框您可以创建命名为MyDialog的新的有状态小部件.>它使用下拉菜单,但您可以以相同的方式实现收音机小部件).

As I said the above comment showDialog creates new context and that setState on the calling widget therefore won't affect the dialog You can create new stateful widget naming MyDialog.Checkout this gist such that you can get it(it uses dropdown but you can implement radio widget in same way).

这篇关于Flutter中的AlertDialog小部件内的单选按钮小部件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆