flutter—Dialog使用 WillPopScope + Future.value(false)屏蔽返回键

2021-08-02 17:55:46 浏览数 (1)

使用 WillPopScope Future.value(false); 屏蔽返回键。代码如下:

代码语言:javascript复制
showDialog<Null>(
  context: context, // BuildContext对象
  barrierDismissible: false, // 屏蔽点击对话框外部自动关闭
  builder: (_) => WillPopScope(
        child: AlertDialog(
          content: Text(
            '账户登录信息已过期,是否重新登录?',
          ),
          actions: <Widget>[
            FlatButton(
              child: buildCommonText(
                content: getResString(context, StringIds.dialog_exit),
                fontSize: SIZE14,
                color: color_888,
              ),
              onPressed: () => exitApp(),
            ),
            FlatButton(
              child: buildCommonText(
                content: getResString(context, StringIds.dialog_relogin),
                fontSize: SIZE14,
                fontWeight: FontWeight.w600,
                color: color_FF664B,
              ),
              onPressed: () => super.exitLogin(),
            ),
          ],
        ),
        onWillPop: () async {
          return Future.value(false);
        },
      ),
);

0 人点赞