Flutter-从导航栏更改后退按钮 [英] Flutter - Change back button from Navigation Bar
本文介绍了Flutter-从导航栏更改后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天,
我需要从位于Android手机导航栏上的后退按钮(如imagem波纹管)更改命令吗?
I need to change the command from back button located on Navigation Bar on Android cellphones, like the imagem bellow?
我需要更改按钮以显示消息"Do you really want to quit the application?"
.要确认用户退出程序.
I need to change the button to appear a message, "Do you really want to quit the application?"
.To confirm the user leave the program.
任何人都可以帮忙吗?
谢谢.
推荐答案
使用 WillPopScope 小部件来处理后退按钮操作,例如:
Use the WillPopScope widget to handle the back button action, example :
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"),),
),
);
}
}
这篇关于Flutter-从导航栏更改后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文