Flutter Web:如何在Flutter Web应用程序中禁用浏览器的后退按钮

Flutter Web:如何在Flutter Web应用程序中禁用浏览器的后退按钮

问题描述:

成功登录后,用户将重定向到主页,但是当用户单击浏览器后退按钮时,它很容易重定向到登录屏幕.我应该怎么做才能禁用向后重定向?

After successfully login the user redirected to the Home page but when the user clicks on the browser back button it easily redirected to the login screen. What should I do to disable backward redirection?

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'),
        ),
      ),
    );
  }
}