android - 在 webview 中获取当前 URL

标签 android webview dart flutter

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

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

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

最佳答案

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

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

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

关于android - 在 webview 中获取当前 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54884061/

相关文章:

http - flutter http get - 为什么在访问 NodeMCU 上运行的服务器时会得到 "Invalid request method"?

java - 加载 url web view android - Java

android - 在 Android 中水平和垂直滚动 ListView

javascript - 如何在 Android 后台运行 WebView?

android - 在 Webview 中缩放图像

flutter - 为什么在initState()之前调用有状态的小部件build()函数?

flutter - 如何从子无状态小部件设置有状态小部件的状态

android - 更改 ndk-build 输出位置

android - 标记在结束拖动时显示信息窗口

swift - 检测 Web View 上文本的链接