执行flutter pub get未下载pubspec.yaml指定依赖的问题求助
问题描述
在Mac系统的VS Code中开发Flutter应用,已在pubspec.yaml中添加flutter_tex: ^4.0.13等依赖,但执行flutter pub get时未下载flutter_tex及后续添加的其他依赖。尝试过重启VS Code与电脑、执行flutter clean、flutter packages get/upgrade、flutter pub cache repair、重启Dart分析服务器等操作,问题仍未解决。
当前pubspec.yaml依赖配置:
dependencies: flutter: sdk: flutter flutter_tex: ^4.0.13 webview_flutter: ^4.10.0 cupertino_icons: ^1.0.8
flutter pub get执行输出:
Resolving dependencies... Downloading packages... async 2.11.0 (2.12.0 available) boolean_selector 2.1.1 (2.1.2 available) characters 1.3.0 (1.4.0 available) clock 1.1.1 (1.1.2 available) collection 1.19.0 (1.19.1 available) fake_async 1.3.1 (1.3.2 available) leak_tracker 10.0.7 (10.0.8 available) leak_tracker_flutter_testing 3.0.8 (3.0.9 available) matcher 0.12.16+1 (0.12.17 available) material_color_utilities 0.11.1 (0.12.0 available) meta 1.15.0 (1.16.0 available) path 1.9.0 (1.9.1 available) source_span 1.10.0 (1.10.1 available) stack_trace 1.12.0 (1.12.1 available) stream_channel 2.1.2 (2.1.4 available) string_scanner 1.3.0 (1.4.1 available) term_glyph 1.2.1 (1.2.2 available) test_api 0.7.3 (0.7.4 available) vm_service 14.3.0 (15.0.0 available) Got dependencies! 19 packages have newer versions incompatible with dependency constraints. Try `flutter pub outdated` for more information.
flutter pub outdated执行输出:
Showing outdated packages. [*] indicates versions that are not the latest available. Package Name Current Upgradable Resolvable Latest direct dependencies: all up-to-date. dev_dependencies: all up-to-date. transitive dependencies: characters *1.3.0 *1.3.0 *1.3.0 1.4.0 collection *1.19.0 *1.19.0 *1.19.0 1.19.1 material_color_utilities *0.11.1 *0.11.1 *0.11.1 0.12.0 meta *1.15.0 *1.15.0 *1.15.0 1.16.0 path *1.9.0 *1.9.0 *1.9.0 1.9.1 transitive dev_dependencies: async *2.11.0 *2.11.0 *2.11.0 2.12.0 boolean_selector *2.1.1 *2.1.1 *2.1.1 2.1.2 clock *1.1.1 *1.1.1 *1.1.1 1.1.2 fake_async *1.3.1 *1.3.1 *1.3.1 1.3.2 leak_tracker *10.0.7 *10.0.7 *10.0.7 10.0.8 leak_tracker_flutter_testing *3.0.8 *3.0.8 *3.0.8 3.0.9 matcher *0.12.16+1 *0.12.16+1 *0.12.16+1 0.12.17 source_span *1.10.0 *1.10.0 *1.10.0 1.10.1 stack_trace *1.12.0 *1.12.0 *1.12.0 1.12.1 stream_channel *2.1.2 *2.1.2 *2.1.2 2.1.4 string_scanner *1.3.0 *1.3.0 *1.3.0 1.4.1 term_glyph *1.2.1 *1.2.1 *1.2.1 1.2.2 test_api *0.7.3 *0.7.3 *0.7.3 0.7.4 vm_service *14.3.0 *14.3.0 *14.3.0 15.0.0 all dependencies are up-to-date.
问题分析与解决建议
从输出看,flutter pub get显示"Got dependencies!"且flutter pub outdated标记所有直接依赖为"up-to-date",说明Pub认为这些依赖已经存在,但实际项目中找不到它们,大概率是以下原因:
- 依赖已缓存但未链接到项目:Pub会将下载的包缓存到本地(Mac路径一般是
~/.pub-cache),可能缓存中已有flutter_tex和webview_flutter,但项目的.dart_tool目录损坏导致链接失效。 - 版本约束隐性冲突:当前Flutter SDK版本与指定的
flutter_tex版本存在兼容问题,Pub自动处理冲突但未明确提示,导致依赖未正常部署到项目。
试试这些步骤:
- 彻底清理项目缓存:删除项目根目录下的
.dart_tool、build文件夹,执行flutter clean后重新运行flutter pub get。 - 强制重新下载依赖:先执行
flutter pub get --offline确认缓存是否可用,若不行,执行flutter pub cache clean清空本地缓存,再重新执行flutter pub get。 - 检查SDK兼容性:查看
flutter_tex: ^4.0.13的版本要求,执行flutter --version确认当前SDK版本,若不兼容则升级或降级Flutter。 - 手动添加本地依赖:从官方仓库下载对应版本的包,解压到项目
packages目录,在pubspec.yaml中指定本地路径,示例:flutter_tex: path: ./packages/flutter_tex-4.0.13 webview_flutter: path: ./packages/webview_flutter-4.10.0 - 重置VS Code插件:打开VS Code扩展面板,更新Dart和Flutter插件,禁用后重新启用,再重启编辑器。
内容的提问来源于stack exchange,提问作者kettle corn with a Q U
相关产品推荐
相关产品推荐

