嘿,我正在尝试创建一个屏幕,显示带有底部应用栏的网络视图。
因此,您加载网络视图,当点击底部应用栏中的某个项目时,其他网站应该加载到同一个网络视图中......
除了我最初解析的网站之外,我不知道如何打开另一个网站。
我尝试使用“setState”更新网址,但它只更新应用栏标题,并且网络视图仍然显示原始网站
这是我当前的代码:
class _WebviewContainer extends State<WebviewContainer> {
var url;
final key = UniqueKey();
_WebviewContainer(this.url);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(url),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.home,
size: 40.0,
color: Colors.white,
),
onPressed: () => {
//-> Here I set the new url but the webview always shows the origin website
setState(() {
url = 'https://stackoverflow.com/';
})
},
)
],
),
body: Column(
children: <Widget>[
Expanded(
child: WebView(
key: key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: url,
),
),
],
),
);
}
}
我从 YouTube 上的教程中获取了代码,创建者还指出,如果 url 的状态发生变化,webview 将重新加载,但不幸的是他没有展示如何做到这一点
如果有人可以帮助我吗?