Web control browser back button

Viewed 478

I'm using Navigation 2 and setUrlStrategy(PathUrlStrategy()); I added WillPopScope but the onWillPop is not called when clicking the browser's back button.

  Widget build(context) {
return WillPopScope(
  onWillPop: () async {
    print('here');
    if (currentStep == 0) {
      return false;
    }
    return true;
  },
  child: Scaffold(...
1 Answers

In Navigator 2.0, web browsers are chronological and basically treat all navigation as pushes.

Scenario:

  1. Navigate from screen 1 to screen 2
  2. Click the browser's back button.

In this scenario, Flutter will push the previous route (screen 1) onto the stack.

In other words, the browser back button no longer triggers onPopRoute. Instead it triggers onPushRoute.

I believe it was designed this way so that every navigation action can be treated as a deeplink. With that in mind, if you're developing a Flutter app for the web you should avoid passing arguments from one route to another as much as possible.

https://github.com/flutter/flutter/issues/71122#issuecomment-733864359

Related