In Flutter i write simple dialog for loader during async task. when i touch outside dialog dismissed, How can I stop this behaviour ?
Code
showDialog( context: context, builder: (_) => new Dialog( child: new Container( alignment: FractionalOffset.center, height: 80.0, padding: const EdgeInsets.all(20.0), child: new Row( mainAxisSize: MainAxisSize.min, children: [ new CircularProgressIndicator(), new Padding( padding: new EdgeInsets.only(left: 10.0), child: new Text("Loading"), ), ], ), ), ));
Any help will be appreciated, thank you in advance.
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. By default, if you do not provide any value to barrierDismissable property, alert dialog closes when user taps on the area outside the alert.
There is a property inside showDialog called barrierDismissible . Setting this value to false will make your AlertDialog not closable by clicking outside.
If you don't want to return any result after showDialog is closed, you can use it. Navigator. pop(context);
In its on the pressed property, we have to use the showDialog widget of flutter. It takes context and a builder. In builder, we provide the AlertDialog widget with title, content(Description of a title), and actions (Yes or no buttons), and our alert dialog box is ready to use.
There's a property called barrierDismissible
that you can pass to showDialog
; which makes dialogs dismissible or not on external click
showDialog( barrierDismissible: false, builder: ... )
If you want to prevent dialog close when back button pressed then refer below code. You have to wrap your AlertDialog in WillPopScope widget and make onWillPop property value with function which return Future.value(false).
showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { return WillPopScope( onWillPop: () => Future.value(false), child:AlertDialog( title: new Text("Alert Title"), content: new SingleChildScrollView( child: Container(),), actions: <Widget>[ new FlatButton( child: new Text("Close"), onPressed: () { }, ), ], ) ) }, );
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