How to dismiss an AlertDialog on a FlatButton click?

前端 未结 16 1312
轮回少年
轮回少年 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:09

    Creating a separate context for Alert Dialog would help.

    showDialog(
      context: context,
      builder: (alertContext) => AlertDialog(
        title: const Text("Location disabled"),
        content: const Text(
            """Location is disabled on this device. Please enable it and try again."""),
        actions: [
          new FlatButton(
            child: const Text("Ok"),
            onPressed: () => Navigator.pop(alertContext),
          ),
        ],
      ),
    );
    

提交回复
热议问题