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

Flutter 3.22.0打包APK报错:找不到WebViewController构造函数

解决Flutter 3.22.0构建APK时flutter_html的WebView相关报错问题

问题原因

你遇到的找不到构造函数'WebViewController'和方法'WebViewWidget'错误,本质是flutter_html依赖的webview_flutter版本与项目中的版本不兼容:

  • WebViewWidget和新版WebViewController是webview_flutter 4.0.0及以上版本才引入的API,旧版本(如3.x)使用的是WebView组件和不同的控制器初始化方式。
  • 你依赖的flutter_html仓库master分支大概率适配了webview_flutter 4.x+,但你的项目中可能间接依赖了更低版本的webview_flutter,或因依赖冲突导致实际使用的版本不满足要求。

解决方案

方案1:升级webview_flutter到兼容版本

在pubspec.yaml中显式添加适配Flutter 3.22.0的webview_flutter版本:

dependencies:
  # 保留原有依赖,新增以下内容
  webview_flutter: ^4.4.0

执行命令更新依赖:

flutter pub get

方案2:替换为flutter_html官方稳定版

你当前使用的是第三方fork的仓库,可能存在兼容性问题。替换为官方稳定版:

dependencies:
  # 删除原有的git依赖,替换为以下内容
  flutter_html: ^3.0.0-beta.2 # 或适配Flutter3.22的最新稳定版

执行flutter pub get后重新构建。

方案3:强制指定webview_flutter版本(解决依赖冲突)

如果项目中其他依赖拉低了webview_flutter版本,在dependency_overrides中强制锁定版本:

dependency_overrides:
  # 保留原有override,新增以下内容
  webview_flutter: ^4.4.0

更新依赖后重新构建:

flutter pub get
flutter build apk --release

方案4:清理缓存重试

若以上方法无效,清理Flutter缓存后重新操作:

flutter clean
flutter pub get
flutter build apk --release

内容的提问来源于stack exchange,提问作者Ashfaq Manu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 18:13:17