美好的一天,
我需要从位于Android手机导航栏上的后退按钮(如imagem波纹管)更改命令吗?
我需要更改按钮以显示消息"Do you really want to quit the application?"
。要确认用户退出该程序。
有人可以帮忙吗?
谢谢。
答案 0 :(得分:1)
使用WillPopScope小部件来处理后退按钮动作,例如:
class TestingWidget extends StatefulWidget {
@override
TestingWidgetState createState() {
return new TestingWidgetState();
}
}
class TestingWidgetState extends State<TestingWidget> {
Future<bool> _onBackPressed(){
final alertDialog = AlertDialog(
content: Text("Do you really want to quit the application?"),
actions: <Widget>[
FlatButton(
child: Text('Yes'),
onPressed: () => Navigator.of(context).pop(),
),
FlatButton(
child: Text('No'),
onPressed: () => Navigator.of(context).pop(),
)
],
);
showDialog(
barrierDismissible: false,
context: context,
builder: (context) => alertDialog);
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: _onBackPressed,
child: Scaffold(
appBar: AppBar(),
body: Center(child: Text("Hello world"),),
),
);
}
}