1 2 3 4 5 6 7 8 9 10 11 12 13 14
| @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async => showDialog( context: context, builder: (context) => AlertDialog(title: Text('你确定要退出吗?'), actions: <Widget>[ RaisedButton(child: Text('退出'), onPressed: () => Navigator.of(context).pop(true)), RaisedButton(child: Text('取消'), onPressed: () => Navigator.of(context).pop(false)),])), child: Scaffold( appBar: AppBar(title: const Text('Flutter WillPopScope demo'),), body: Container(alignment: Alignment.center, child: Text('点击后退按钮,询问是否退出。'),), )); }
|