Alex Vincent's Blog

Alex's Blog
Where he writes his thoughts and experiences.
  1. 首页
  2. 默认分类
  3. 正文

Flutter Dialog 禁止返回键返回

4月 21, 2019 8919点热度 16人点赞 0条评论

在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();
                    },
                  )
                ],
              )
          );
        });
  }
标签: 暂无
最后更新:4月 21, 2019

Alex Li

He's less to speak.

点赞
< 上一篇
下一篇 >

COPYRIGHT © 2023 Alex Li. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

桂ICP备16008143号-1