How to dismiss an AlertDialog on a FlatButton click?

前端 未结 16 1317
轮回少年
轮回少年 2021-02-03 16:44

I have the following AlertDialog.

showDialog(
            context: context,
            child: new AlertDialog(
              title: const Text(\"Lo         


        
16条回答
  •  再見小時候
    2021-02-03 17:17

    The accepted answer states how to dismiss a dialog using the Navigator Class. To dismiss a dialog without using Navigator you can set the onPressed event of the button to the following:

    setState((){
      thisAlertDialog = null; 
    });
    

    In case the code above is not self-explanatory it is basically setting the Parent AlertDialog of the FlatButton to null, thus dismissing it.

提交回复
热议问题