webflutter

Flutter Web: How to disable backward button of browser in flutter web application


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?


Solution

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