在showDialog方法中,安卓机型点击返回键,barrierDismissible不能阻止dialog pop,需要传异步方法进onWillPop,示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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(); }, ) ], ) ); }); } |