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

Ola*_*nce 5 web flutter

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

Fed*_*han 4

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'),
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)