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")]), );
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.
To close the opened Dialog , you can use the Get. back function. Get. back();
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.
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.
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 justNavigator.pop(context, result)
.
so I'd assume one of these two should do what you want.
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);
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