Disclaimer: I am not the owner of the answer. I am just posting answer from reference: https://iiro.dev/resolving-dart-package-version-conflicts/
This helped me.
Let's say you have problem like this:
Because intl_translation 0.17.0 depends on petitparser ^1.1.3 and xml >=3.2.0
depends on petitparser ^2.0.0, intl_translation 0.17.0 is incompatible with xml >=3.2.0.
So, because my_project depends on both xml ^3.2.0 and intl_translation 0.17.0,
version solving failed.
The pubspec file might look a little something like this:
pubspec.yaml
dependencies:
# ...
xml: ^3.2.0
intl_translation: ^0.17.0
Solution:
The fastest way to resolve this problem is to set the versions of both of the conflicting dependencies to any
.
pubspec.yaml
dependencies:
# ...
xml: any # <- don't leave me like this - read further!
intl_translation: any # <- don't leave me like this either!
^^This is not solution, there is one more step!
The output might like below:
Resolving dependencies...
Got dependencies!
After getting the project to build, you should tighten the dependency versions back to use semantic versioning like they previously did.
Open the generated pubspec.lock
file and find the dependencies that were previously conflicting.
pubspec.lock
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
xml:
# ...
version: "3.0.1" # the version of "xml" package that worked fine
# with "intl_translation".
intl_translation:
# ...
version: "0.17.0" # the version of "intl_translation" package
# that worked fine with "xml".
From that lockfile, we can see that the xml package version 3.0.1 and intl_translation package version 0.17.0 play along together well.
As the last step, replace any with the correct versions on your pubspec file:
pubspec.yaml
dependencies:
# ...
xml: ^3.0.1
intl_translation: ^0.17.0
Refetch your dependencies one last time by running flutter packages get
to verify that this does indeed work and then you’re good to go.
Answer credits: Iiro Krankka