如何将AlertDialog设置为不在flutter中关闭外部

Joã*_*ili 8 android-alertdialog flutter

我建立了一个AlertDialog来显示加载,而我正在验证用户,当它完成后我弹出它.

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

但是,如果用户点击对话框外,它会关闭.因此,当auth完成时,它仍会弹出一些东西(我猜是脚手架),打破了应用程序.如何让Dialog不能关闭?

Vin*_*mar 20

里面有一个showDialog叫做的房产barrierDismissible.将此值设置为false将使您的AlertDialog无法通过单击外部关闭.

showDialog(
   ...
   barrierDismissible: false,
   ...
Run Code Online (Sandbox Code Playgroud)

  • 好的。棘手的部分是,出于某种原因,我认为这个属性将是“AlertDialog”的一部分(可能是 Android 习惯)。不过,这样更有意义。 (2认同)

Cop*_*oad 11

为了防止按下后退按钮时关闭对话框,您还应该将您的AlertDialog(或任何其他小部件)包装在WillPopScope.

showDialog(
  context: context,
  barrierDismissible: false, // <-- Set this to false.
  builder: (_) => WillPopScope(
    onWillPop: () async => false, // <-- Prevents dialog dismiss on press of back button.
    child: AlertDialog(...),
  ),
);
Run Code Online (Sandbox Code Playgroud)