You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用webview_flutter包点击AppBar按钮刷新WebView无响应求助

解决webview_flutter点击刷新按钮无响应的问题

你的代码存在两个关键问题导致刷新无效:

  • 新建的reloadController是独立的控制器实例,和页面中WebViewWidget绑定的widgetController没有任何关联,调用它的reload()不会影响实际显示的WebView。
  • IconButton的onPressed回调只是返回了控制器实例,没有执行刷新方法。

修复后的代码

直接使用和WebView绑定的widgetController调用reload()即可:

return Scaffold(
  appBar: AppBar(
    title: Text(utf8decoder.convert(widget.title.codeUnits)),
    backgroundColor: hexToColor(user!.templateColorPrimary),
    actions: [
      IconButton(
        onPressed: () => widgetController.reload(),
        icon: const Icon(Icons.refresh),
      )
    ],
  ),
  body: WebViewWidget(controller: widgetController),
);

额外说明

确保widgetController已经完成正确初始化并加载了目标网页,比如在父组件中应该有类似这样的初始化逻辑:

final WebViewController widgetController = WebViewController()
  ..loadRequest(Uri.parse("https://你的目标网页地址"));

内容的提问来源于stack exchange,提问作者Vitor Dalefi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 21:50:37