在Webview中获取当前URL

时间:2019-02-26 11:03:46

标签: android webview dart flutter

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

WebView:

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

是否有从current URL或其他方法中获取webview的功能?请帮忙。

1 个答案:

答案 0 :(得分:1)

您的重新加载按钮足以使用Future<Null> reload();吗?这似乎重新加载了当前网址。因此,您不必显式设置网址。

您必须将函数的调用更改为

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