androidiosflutterflutter-alertdialog

How to dismiss an AlertDialog on a FlatButton click?


I have the following AlertDialog.

showDialog(
            context: context,
            child: new 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: _dismissDialog,
                ),
              ],
            ),
        );

How can I make _dismissDialog() dismiss said AlertDialog?


Solution

  • Navigator.pop() should do the trick. You can also use that to return the result of the dialog (if it presented the user with choices)