How to set AlertDialog to don't close clicking

2019-06-28 03:21发布

问题:

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?

回答1:

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


回答2:

// User Defined Function void _showloding() {

// flutter defined function
showDialog(
  barrierDismissible: false, // JUST MENTION THIS LINE
  context: context,
  builder: (BuildContext context) {
    // return object of type Dialog
    return AlertDialog(
      content: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Container(height: 100,width: 100,child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Center(child: SizedBox(height: 50,width: 50,child: CircularProgressIndicator())),
            Padding(
              padding: const EdgeInsets.only(top: 20),
              child: Center(child: Text("Processing")),
            )
          ],
        )),
      )
    );
  },
);

}