首页 > 解决方案 > 添加新的依赖项之间的冲突

问题描述

这些是我在我的依赖项pubspec.yaml

  dependencies:
   ...
   image_picker: ^0.8.4+2
   ...

一切正常,但现在我添加了这个:

  dependencies:
   ...
   image_picker: ^0.8.4+2
   ...
   image_editor_pro: ^1.1.8

运行 pub get 我有这个错误:

因为 image_editor_pro >=1.1.0 依赖于 image_picker ^0.7.4 而 provauth 依赖于 image_picker ^0.8.4+2,所以 image_editor_pro >=1.1.0 是被禁止的。所以,由于 provauth 依赖于 image_editor_pro ^1.1.8,版本求解失败。pub get failed (1; 所以,因为 provauth 依赖于 image_editor_pro ^1.1.8,版本求解失败。)

我尝试降级我的 image_picker 版本,但出现新错误:

无法打开文件,路径 = 'C:\Users\loren\flutter.pub-cache_temp\dir60565baa\test\fixtures\invalid\n_structure_<.>.json' (操作系统错误:文件名的语法,目录or of volume is not correct (This is my bad translation of the error). , errno = 123) pub get failed (66; , errno = 123))

我能做些什么来解决和使用这两个依赖项?

标签: flutterdartflutter-dependencies

解决方案


您可以尝试覆盖依赖项,以便您的项目仅使用一个版本。像这样的东西:

name: your_app

dependencies:
  image_picker: ^0.8.4+2
  image_editor_pro: ^1.1.8

dependency_overrides:
  image_picker: '0.8.4+2'  # Use only this version for all the code depended on image picker

但是您需要彻底测试依赖于被覆盖依赖项的库,以检查它是否不会给您带来新错误。

https://dart.dev/tools/pub/dependencies#dependency-overrides


推荐阅读