【bug总结】在Flutter中阻止对话框关闭外部触摸

588 阅读1分钟

使用 WillPopScope + Future.value(false); 屏蔽返回键。

代码如下:

showDialog<Null>(
  context: context, // BuildContext对象
  barrierDismissible: false, // 屏蔽点击对话框外部自动关闭
  builder: (_) => WillPopScope(
        child: AlertDialog(
          content: Text(
            'xxx',
          ),
          actions: <Widget>[
           
          ],
        ),
        onWillPop: () async {
          return Future.value(false);
        },
      ),
);