繁体   English   中英

如何在 flutter 的 alertDialog 中使用 checkboxlisttile?

[英]How can I use checkboxlisttile in alertDialog in flutter?

当我尝试在警报对话框中使用复选框列表时遇到问题。 我可以看到列表图块,但是当我单击它时它不会改变任何东西,不会有勾号。

bool imp = false
Future _showAlert(BuildContext context) {
return showDialog(
  context: context,
  child: AlertDialog(
    title: Text('Add'),
    content: Container(
      child: Column(
        children: <Widget>[
          TextField(),
          CheckboxListTile(
            title: Text('Important:'),
            value: imp,
            onChanged: (value) {
              setState(() {
                imp = value;
              });
            },
          ),
        ],
      ),
    ),
  ),
);

}

只需将这 2 行添加到您的 onchange 方法中

    onChanged: (value) {

                  setState(() {
                    imp = value;
                  });
                  Navigator.of(context).pop(); // Line 1
                  _showAlert(context) ;// Line 2
                },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM