I have the following AlertDialog
.
showDialog(
context: context,
child: new AlertDialog(
title: const Text(\"Lo
Navigator.of(context, rootNavigator: true).pop('dialog')
worked with me.
If you don't want to return any result, use either of them:
Navigator.of(context).pop();
Navigator.pop(context);
But if you do want to return some result, see this
Example:
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text('Wanna Exit?'),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context, false), // passing false
child: Text('No'),
),
FlatButton(
onPressed: () => Navigator.pop(context, true), // passing true
child: Text('Yes'),
),
],
);
}).then((exit) {
if (exit == null) return;
if (exit) {
// user pressed Yes button
} else {
// user pressed No button
}
});
Navigator.pop(_)
worked for me, but the Flutter Team's gallery contains an example using:
Navigator.of(context, rootNavigator: true).pop()
which also works, and I am tempted to follow their lead.
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)
pass it in the showDialog
barrierDismissible : true
Generally Navigator.pop(context);
works.
But If the application has multiple Navigator objects and dialogBox
doesn't close, then try this
Navigator.of(context, rootNavigator: true).pop();
If you want to pass result call, try
Navigator.pop(context,result);
OR
Navigator.of(context, rootNavigator: true).pop(result)