How to solve dependency issues after a `flutter upgrade`?

607 views Asked by At

I struggled to fix all the dependencies issues I had after the upgrade.

there is still one regarding

$ flutter pub get

Resolving dependencies...
Because no versions of i18n_extension match >9.0.2 <10.0.0 and i18n_extension 9.0.2 depends on sprintf ^7.0.0, i18n_extension ^9.0.2 requires sprintf ^7.0.0.
And because optimized_cached_image >=3.0.0 depends on sprintf ^6.0.0, i18n_extension ^9.0.2 is incompatible with optimized_cached_image >=3.0.0.
So, because shokaze depends on both i18n_extension ^9.0.2 and optimized_cached_image ^3.0.0, version solving failed.
exit code 1

And here is the yaml (I removed all the unnecessary lines for convenience):

environment:
  sdk: '>=2.18.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  intl: ^0.18.0 #^0.17.0
  i18n_extension: ^9.0.2 #^5.0.1
  optimized_cached_image: ^3.0.0 #^3.0.1

I don't explicitly ask for sprintf.

How could I solve the dependency issues?

2

There are 2 answers

0
70ny On BEST ANSWER

This is a common problem in Flutter, and it's happening because the packages i18n_extension and optimized_cached_image depend on different versions of the sprintf package. Specifically, i18n_extension depends on version ^7.0.0 of sprintf, while optimized_cached_image depends on version ^6.0.0. This causes a conflict because the two packages require different versions of the same dependency.

Here's a few ways to resolve this issue:

  1. Upgrade or downgrade one of the packages - Check the pub.dev listings for i18n_extension and optimized_cached_image to see if there's a newer version of either package that resolves the dependency conflict. If a newer version isn't available, you might consider downgrading one of the packages if it's compatible with your project.

  2. Override the dependency - You can override the sprintf version in your pubspec.yaml file to use a specific version. This should only be done as a last resort, because it can lead to unexpected behavior if the overridden version isn't compatible with all packages that depend on it. Here's an example of how to do this:

dependency_overrides:
  sprintf: ^7.0.0
  1. Ask the package maintainers - If neither of the above options work, you can open an issue on the GitHub page for one of the packages (whichever one you think should update their sprintf dependency) and ask the maintainers to update the package to use a version of sprintf that's compatible with the other package.

Remember to run flutter pub get after making changes to your pubspec.yaml file to update your dependencies

0
Ercross On

You can vendor some of packages using the outdated dependencies using package Vendor. Here's a step-by-step article on how to vendor a package and publish it on pub.

Another helpful article about resolving dependency-hell (DLL) error in your code.