【问题标题】:Get current URL in webview在 webview 中获取当前 URL
【发布时间】:2019-07-19 21:51:59
【问题描述】:

我正在使用 Flutter WebView Plugin 在 Flutter 应用程序中创建 webview。 我在appBar 中添加了一个reload 图标。为了使reload 图标起作用,我想从webview 获取current URL

网络视图:

return new MaterialApp(
      theme
        : new ThemeData(
        primaryColor: Color.fromRGBO(58, 66, 86, 1.0), fontFamily: 'Raleway'),
      routes: {
        "/": (_) => new WebviewScaffold(
          url: url,
          appBar: new AppBar(
            title: Text(title),
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.refresh, color: Color.fromRGBO(255, 255, 255, 1.0),),
                onPressed: () => flutterWebviewPlugin.reloadUrl(url), // this is reloading the url that was provided to webview, not the current URL.
              )
            ],
          ),
          withJavascript: true,
          withLocalStorage: true,
          appCacheEnabled: true,
          hidden: true,
          initialChild: Container(
            child: const Center(
              child: CircularProgressIndicator(),
            ),
          ),
        )
      },
    );

是否有任何函数可以从webview 或任何其他方法获取current URL?请帮忙。

【问题讨论】:

    标签: android webview dart flutter


    【解决方案1】:

    您的重新加载按钮使用Future&lt;Null&gt; reload(); 是否足够?这似乎重新加载了当前的 url。所以你不必显式设置 url。

    你必须把函数的调用改为

    onPressed: () => flutterWebviewPlugin.reload(), // this is reloading the url that was provided to webview, not the current URL. )
    

    【讨论】:

      猜你喜欢
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多