使用 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);
},
),
);