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
?
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:
In case the code above is not self-explanatory it is basically setting the Parent AlertDialog of the FlatButton to null, thus dismissing it.
If you don't want to return any result, use either of them:
But if you do want to return some result, see this
Example:
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)Example of dismissing alert dialog on flat button click
Above code have two unique things which is used to provide callback result of dialog
Based on these return value, we can perform some operation outside of it or maintain the dialog status value
worked with me.
This works Prefectly