How to dismiss an AlertDialog on a FlatButton click?


I have the following AlertDialog.

            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?


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)

Answered By – Collin Jackson

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published