【问题标题】:How to configure go back button in Browser for Flutter Web App如何在浏览器中为 Flutter Web App 配置返回按钮
【发布时间】:2020-08-02 22:24:42
【问题描述】:

我不是在问 webview。这是关于 Flutter Web 应用程序的。当用户按下浏览器内置的返回按钮时,我需要返回特定页面。

有什么猜测吗?

当我按下返回按钮时出现此错误

Error: Assertion failed: org-dartlang- 
    sdk:///flutter_web_sdk/lib/_engine/engine/history.dart:110:14 
    _userProvidedRouteName != null
    is not true
        at Object.throw_ [as throw] (http://localhost:8300/dart_sdk.js:4770:11)
        at Object.assertFailed (http://localhost:8300/dart_sdk.js:4721:15)

【问题讨论】:

标签: flutter web-applications flutter-web


【解决方案1】:

如果您不想导航到新页面

    @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async => true,
      child: Scaffold(

        key: _scaffold,
        backgroundColor: Colors.indigo,
        body: Center(
          child: Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                registerForm(),
                registerBtn(),
                SizedBox(height: 30,),
                _buildSignInButton()
              ],
            ),
          ),
        ),
      ),
    );
  }

【讨论】:

  • 谢谢!疯狂地试图找到解决方案。
  • 很高兴知道它对您有用!
【解决方案2】:

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

【讨论】:

    【解决方案3】:
    onWillPop: () {
      Navigator.pop(context);
      return new Future(() => true);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-04-04
      • 2011-07-11
      • 1970-01-01
      • 2020-05-02
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 2019-12-28
      相关资源
      最近更新 更多