用户成功登录后,将被重定向到主页,但当用户单击浏览器的“返回”按钮时,很容易被重定向回登录界面。我该怎么做才能禁用后退重定向?
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
/// Hope WillPopScope will do the job for you.
return WillPopScope(
onWillPop: () async => null,
child: Scaffold(
body: Center(
child: Text('asd'),
),
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
/// Hope WillPopScope will do the job for you.
return WillPopScope(
onWillPop: () async => false, // update here
child: Scaffold(
body: Center(
child: Text('asd'),
),
),
);
}
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: MaterialApp(
...
),
);
}
}
onWillPop
不会触发。有什么方法可以防止回到登录屏幕? - tmaihoff