How to dismiss an AlertDialog on a FlatButton click?

Question

Asked by Gustash on May 24, 2017 (source).

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?

Answer

Question answered by Collin J (source).

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)

ANDROID FLUTTER FLUTTER-ALERTDIALOG IOS
SHARE: