Flutter Dialog 屏蔽返回键

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

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);
},
),
);
posted @ 2019-04-30 15:39  ytymz  阅读(4631)  评论(0编辑  收藏  举报