I have problem with showDialog, when i press nothing happens but if i use Navigator.pushNamed(context, "/screen1")
it works. I can not run Navigator.pop(context)
, it does not return any errors.
_showDialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text("Alert Dialog title"),
actions: <Widget>[
new FlatButton(
child: new Text("Back"),
onPressed: () {
//Navigator.pushNamed(context, "/screen1");
Navigator.pop(context);
},
),
],
);
});}
In my build() :
IconButton(
iconSize: 30.0,
onPressed: () => _showDialog(context),
icon: Icon(
Icons.clear,
color: Colors.white,
),
)
You can put your Dialog on to screen as other widgets, or pop up it via showDialog() function, showDialog() is standalone function. Dialog has three origin classes is Dialog, AlertDialog, SimpleDialog.
If you don't want to return any result after showDialog is closed, you can use it. Navigator. pop(context);
Simply use await or then . the code in then block will be run after the dialog is dismissed.
had the same issue .having useRootNavigator: false,
in showDialog params solved my issue .
Use pop() two times:-
Navigator.of(context).pop(); Navigator.of(context).pop();
Reason: first pop function dismiss the dialog and Second pop function close the screen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With