flutterdartpackagepubspec

Flutter pubspec dependency conflict


I've a wired problem with resolving dependencies. In my application pubspec I've following lines:

dependencies:
  yet_another_layout_builder: ^0.1.0

dev_dependencies:
  hive_generator: ^1.1.1

both packages uses analyzer package and flutter pub get reports me an error:

Because no versions of hive_generator match >1.1.1 <2.0.0 and hive_generator 1.1.1 depends on analyzer >=1.0.0 <3.0.0, hive_generator ^1.1.1 requires analyzer >=1.0.0 <3.0.0.

And because every version of yet_another_layout_builder depends on analyzer ^3.0.0, hive_generator ^1.1.1 is incompatible with yet_another_layout_builder.

So, because testApp depends on both yet_another_layout_builder ^0.1.0 and hive_generator ^1.1.1, version solving failed.

pub get failed (1; So, because testApp depends on both yet_another_layout_builder ^0.1.0 and hive_generator ^1.1.1, version solving failed.)

However when I look into github sources for those packages, it looks for me that this error shouldn't happen. For hive_generator pubspec have following restrictions:

dependencies:
  analyzer: ">=1.0.0 <4.0.0"

and for YetAnotherLayoutBuilder pubspec have:

dependencies:
  analyzer: ^3.0.0

So if I understands this notation correctly:

Any suggestions where I'm mistaken are gladly welcome.


Solution

  • Right now neither hive_generator plugin have any upgrade to this version nor yet_another_layout_builder has downgrade version. So to tackle these kinds of scenarios, we have another method to add dependencies in Flutter which is dependency_overrides using this we can override some dependencies so that our app can use another version of the same dependency as well. So just add below code to your pubspecs.yaml file

    dependency_overrides:
      analyzer: ^2.8.0