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

执行flutter upgrade时遭遇Unable to create dart snapshot错误求助

Flutter升级失败修复方案

错误说明

执行flutter upgrade时出现编译错误,导致Flutter工具无法生成快照,项目完全无法运行。核心问题是Pub缓存中的http包0.13.6版本存在代码错误(拼写错误drethrow、非空返回值未正确实现)。

解决步骤

  • 清理Pub缓存:删除本地Pub缓存目录。Windows路径为%LOCALAPPDATA%\Pub\Cache,Mac/Linux路径为~/.pub-cache,直接删除该文件夹即可。
  • 重建Flutter工具:执行flutter doctor命令,该命令会自动重新下载并构建Flutter依赖的工具链。
  • 手动修复依赖版本(若上述步骤无效):
    1. 找到Flutter安装目录下的packages/flutter_tool/pubspec.yaml文件。
    2. 将http依赖版本修改为^0.13.4或更高稳定版(例如^0.14.0)。
    3. 进入flutter_tool目录,执行flutter pub get拉取正确依赖。
    4. 重新运行flutter upgrade。
  • 重置Flutter安装:如果以上方法都无效,直接下载对应系统的Flutter稳定版压缩包,覆盖现有安装目录,或重新安装Flutter。

原始报错信息(中文翻译)

执行命令:

flutter upgrade

报错详情:

Building flutter tool...
Running pub upgrade...
Resolving dependencies... (8.1s)
Got dependencies.
AppData/Local/Pub/Cache/hosted/pub.dev/http-0.13.6/lib/src/base_request.dart:144:7: 错误:类 'BaseRequest' 未定义 getter 'drethrow'。
 - 'BaseRequest' 来自包 'package:http/src/base_request.dart'(路径:AppData/Local/Pub/Cache/hosted/pub.dev/http-0.13.6/lib/src/base_request.dart)。
尝试将名称更正为现有 getter 的名称,或者定义一个名为 'drethrow' 的 getter 或字段。
      drethrow;
      ^^^^^^^^
AppData/Local/Pub/Cache/hosted/pub.dev/http-0.13.6/lib/src/base_request.dart:129:28: 错误:必须返回非空值,因为返回类型 'StreamedResponse' 不允许为 null。
 - 'StreamedResponse' 来自包 'package:http/src/streamed_response.dart'(路径:AppData/Local/Pub/Cache/hosted/pub.dev/http-0.13.6/lib/src/streamed_response.dart)。
 Future<StreamedResponse> send() async {
                          ^
Error: Unable to create dart snapshot for flutter tool.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 14:12:25