我正在使用 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/