Flutter Dialog 禁止返回键返回

在showDialog方法中,安卓机型点击返回键,barrierDismissible不能阻止dialog pop,需要传异步方法进onWillPop,示例如下:

Future<Null> showPermissionAlert(BuildContext context) async {
    return showDialog<Null>(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new WillPopScope(
              onWillPop: () async => false,
              child:
               AlertDialog(
                title: Text('Allow the app to always use your location'),
                content: SingleChildScrollView(
                  child: ListBody(
                    children: <Widget>[
                      Text('Something'),
                    ],
                  ),
                ),
                actions: <Widget>[
                  FlatButton(
                    child: Text('doSomething'),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  )
                ],
              )
          );
        });
  }

已发布

分类

作者:

标签