【问题标题】:How to get current URL in Flutter Web App如何在 Flutter Web App 中获取当前 URL
【发布时间】:2019-10-04 20:05:31
【问题描述】:

如何在 Flutter Web App 的用户当前所在的 Flutter Web App 中获取当前 URL?

例如:

app1.website.com app2.website.com

根据web应用用户当前所在的url的结果,我想展示不同的内容。

【问题讨论】:

    标签: flutter dart flutter-web


    【解决方案1】:

    您可以使用 javascript 代码,如下所示:

    import 'dart:js' as js;
    
    FlatButton(
      child: Text("Button"),
      onPressed: () {
        print(js.context['location']['href']);
        js.context.callMethod("alert", [js.context['location']['href']]);
      },
    )
    

    【讨论】:

      【解决方案2】:

      你可以这样找到它:

      import 'dart:html';
      
      var url = window.location.href;
      

      【讨论】:

        【解决方案3】:

        这将为您提供当前网址。

        Uri.base
        

        来自文档:

        在浏览器中运行时,这是当前页面的当前 URL(来自 window.location.href)。 https://api.flutter.dev/flutter/dart-core/Uri/base.html

        【讨论】:

          【解决方案4】:

          Uri.base.path - 指向 Navigator 上的当前路径

          【讨论】:

            猜你喜欢
            • 2021-01-14
            • 1970-01-01
            • 2019-09-23
            • 2010-12-23
            • 1970-01-01
            • 2012-06-06
            • 1970-01-01
            • 1970-01-01
            • 2019-09-04
            相关资源
            最近更新 更多