Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss flutter dialog?

Tags:

dialog

flutter

I am new to flutter, I want to dismiss my dialog after the task completion. I've tried with:

Navigator.pop(context, true);  

But my screen is getting black and dialog is still up there. here is my dialog code.

Dialog _dialog = new Dialog(   child: new Row(     mainAxisSize: MainAsixSize.min,      children: <Widget> [     new CircularProgressIndicator(),      new Text("Loading")]),       );  
like image 448
Ammy Kang Avatar asked Jun 04 '18 15:06

Ammy Kang


People also ask

How do you dismiss a dialog Flutter?

To Dismiss Dialog user needs to make use of an inbuilt class like showDialog. The dialog route created by this method is pushed to the root navigator. If the application has multiple Navigator objects. It may be necessary to call Navigator.

How do I dismiss dialog in GETX Flutter?

To close the opened Dialog , you can use the Get. back function. Get. back();

How do you not dismiss dialog in Flutter?

To make your AlertDialog widget not close when user taps on the screen space outside the alert box, set barrierDismissible property to false in showDialog() helper method.

How do I showDialog in Flutter?

We need the function "showDialog()" to display the Material Dialog on the Page. In Flutter everything is a Widget. So the Dialog is also a Material Design Widget.


2 Answers

https://docs.flutter.io/flutter/material/showDialog.html says

The dialog route created by this method is pushed to the root navigator. If the application has multiple Navigator objects, it may be necessary to call Navigator.of(context, rootNavigator: true).pop(result) to close the dialog rather just Navigator.pop(context, result).

so I'd assume one of these two should do what you want.

like image 179
Günter Zöchbauer Avatar answered Sep 26 '22 06:09

Günter Zöchbauer


This code works for me:

  BuildContext dialogContext;   showDialog(     context: context,     barrierDismissible: false,     builder: (BuildContext context) {       dialogContext = context;       return Dialog(         child: new Row(           mainAxisSize: MainAxisSize.min,           children: [             new CircularProgressIndicator(),             new Text("Loading"),           ],         ),       );     },   );    await _longOperation();   Navigator.pop(dialogContext); 
like image 37
live-love Avatar answered Sep 25 '22 06:09

live-love