有没有办法在特定页面上停用Android后退按钮?
class WakeUpApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Time To Wake Up ?",
home: new WakeUpHome(),
routes: <String, WidgetBuilder>{
'/pageOne': (BuildContext context) => new pageOne(),
'/pageTwo': (BuildContext context) => new pageTwo(),
},
);
}
}
Run Code Online (Sandbox Code Playgroud)
在pageOne上我有一个按钮可以转到pageTwo:
new FloatingActionButton(
onPressed: () {
Navigator.of(context).pushNamed('/pageTwo');
},
)
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我按下Android屏幕底部的后退箭头,我会回到pageOne.我希望这个按钮根本不显示.理想情况下,除非用户将手指按在屏幕上5秒钟,否则我希望没有可能的方法离开此屏幕.(我正在尝试为幼儿写一个应用程序,并希望只有父母能够导航出特定的屏幕).
成功登录后,用户重定向到主页,但当用户单击浏览器后退按钮时,它很容易重定向到登录屏幕。我应该怎么做才能禁用向后重定向?
我正在使用 Navigation 2 并setUrlStrategy(PathUrlStrategy());
添加了它WillPopScope,但onWillPop单击浏览器的后退按钮时不会调用 。
Widget build(context) {
return WillPopScope(
onWillPop: () async {
print('here');
if (currentStep == 0) {
return false;
}
return true;
},
child: Scaffold(...
Run Code Online (Sandbox Code Playgroud)