在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();
},
)
],
)
);
});
}