0

In flutter web, I cant navigate through the back and forward buttons of the browser. It gives the following error:

Error: Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/navigation/history.dart:284:14
_userProvidedRouteName != null
is not true
    at Object.throw_ [as throw] (http://localhost:54382/dart_sdk.js:5344:11)
    at Object.assertFailed (http://localhost:54382/dart_sdk.js:5280:15)
    at _engine.SingleEntryBrowserHistory.new.onPopState (http://localhost:54382/dart_sdk.js:149735:59)
Error: Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/navigation/history.dart:284:14
_userProvidedRouteName != null
is not true
    at Object.throw_ [as throw] (http://localhost:54382/dart_sdk.js:5344:11)
    at Object.assertFailed (http://localhost:54382/dart_sdk.js:5280:15)
    at _engine.SingleEntryBrowserHistory.new.onPopState (http://localhost:54382/dart_sdk.js:149735:59)
Jagadish
  • 1,005
  • 11
  • 30

1 Answers1

0

As stated in this answer:

onWillPop Navigate to a new Page

class webScope extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new WillPopScope(
      onWillPop: () async => Navigator.push(context, MaterialPageRoute(builder: (context) => new NewPageWidget())),
      child: Scaffold(
        appBar: new AppBar(
          title: new Text("webScope"),
        ),
      ),
    );
  }
}

or see the other answer in the question for preventing navigation at all.

ForestG
  • 17,538
  • 14
  • 52
  • 86
  • what if the user can navigate to the same page from different pages so when the user presses the back button he/she should be navigated to the page he or she came from. Like navigator.pop...is this the most efficient way to do this? – Jagadish May 27 '21 at 10:22
  • maybe this article can help you with that: https://medium.com/codechai/flutter-web-and-navigation-history-3feec04bfc80 – ForestG May 27 '21 at 11:19