Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter "showDialog" with Navigator.pop()

Tags:

flutter

dart

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,
 ),

)

like image 222
mfv Avatar asked Sep 21 '18 20:09

mfv


People also ask

How do you pop the showDialog Flutter?

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.

How do I get rid of showDialog Flutter?

If you don't want to return any result after showDialog is closed, you can use it. Navigator. pop(context);

How do I run code after showDialog is dismissed in Flutter?

Simply use await or then . the code in then block will be run after the dialog is dismissed.


2 Answers

had the same issue .having useRootNavigator: false, in showDialog params solved my issue .

like image 120
Yusuf Fathi Avatar answered Sep 22 '22 03:09

Yusuf Fathi


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

like image 23
Rituraj Shakti Avatar answered Sep 24 '22 03:09

Rituraj Shakti