Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent AlertDialog from not closing by clicking outside?

Tags:

flutter

I built an AlertDialog to display Loading while i'm authenticating the user and when it finishes i pop it.

Widget loadingDialog = new AlertDialog( content: new Row(   children: <Widget>[     new CircularProgressIndicator(),     Padding(       padding: const EdgeInsets.only(left: 8.0),       child: new Text("Loading..."),     ),   ], ),); 

But, if the user taps outside the Dialog it closes. So when the auth finishes, it will still pop something (i guess the scaffol), breaking the app. How can i make Dialog not closable?

like image 401
João Pedro Ache Virgili Avatar asked Jun 01 '18 02:06

João Pedro Ache Virgili


People also ask

How do I stop dialog close on click outside flutter?

How do I stop dialog close on click outside Flutter? To prevent the dialog from closing on outside barrier touch, you have to set barrierDismissible to false. It is true by default.

How do I stop dialog closing?

Set the onClickListener during the creation of the dialog to null. Then set a onClickListener after the dialog is shown.

How do you dismiss dialog with click on outside of dialog?

You can use dialog. setCanceledOnTouchOutside(true); which will close the dialog if you touch outside of the dialog. Window window = this.

How do I turn off AlertDialog?

AlertDialog generally consists of the main title, the message, and two buttons, technically termed as a positive button and a negative button. Both positive and negative buttons can be programmed to perform various actions. By default, the negative button lets close the AlertDialog without any additional lines of code.


1 Answers

There is a property inside showDialog called barrierDismissible. Setting this value to false will make your AlertDialog not closable by clicking outside.

showDialog(    ...    barrierDismissible: false,    ... 
like image 106
Vinoth Kumar Avatar answered Oct 21 '22 19:10

Vinoth Kumar