简体   繁体   中英

How can I use checkboxlisttile in alertDialog in flutter?

I am having a problem when I am trying to use a checkboxlisttile in an alertdialog. I can see the list tile, but it doesn't change anything when I click on that, there won't be a tick.

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;
              });
            },
          ),
        ],
      ),
    ),
  ),
);

}

Just Add this 2 lines to your onchange method

    onChanged: (value) {

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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