【问题标题】:Flutter Web - Can't navigate through browser back and forward buttonsFlutter Web - 无法通过浏览器的后退和前进按钮导航
【发布时间】:2021-08-15 11:56:24
【问题描述】:

在 Flutter Web 中,我无法浏览浏览器的后退和前进按钮。它给出了以下错误:

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)

【问题讨论】:

    标签: flutter dart flutter-web


    【解决方案1】:

    this answer中所述:

    onWillPop 导航到新页面

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

    或查看问题中的其他答案以完全阻止导航。

    【讨论】:

    • 如果用户可以从不同的页面导航到同一页面,那么当用户按下后退按钮时,他/她应该被导航到他或她来自的页面。像 navigator.pop 一样……这是最有效的方法吗?
    • 也许这篇文章可以帮助你:medium.com/codechai/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2013-07-31
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    相关资源
    最近更新 更多