成功登录后,用户重定向到主页,但当用户单击浏览器上一步按钮时,它很容易重定向到登录屏幕。要禁用后向重定向,我应该怎么做?
ftf50wuq1#
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'), ), ), ); } }
o7jaxewo2#
更新2023年的@FederickJonathan答案,现在你必须为onWillPop参数返回一个bool值:
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'), ), ), ); } }
您也可以将其 Package 在main.dart中的MaterialApp类中,以便一次为整个应用程序工作,如下所示:
class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async => false, child: MaterialApp( ... ), ); } }
2条答案
按热度按时间ftf50wuq1#
o7jaxewo2#
更新2023年的@FederickJonathan答案,现在你必须为onWillPop参数返回一个bool值:
您也可以将其 Package 在main.dart中的MaterialApp类中,以便一次为整个应用程序工作,如下所示: