Dart Packages: Dependency conflicts - flutter

In a Dart/Flutter project, I have
dependencies:
graphql: '^2.1.1-beta.5'
flutter_bloc: ^3.0.0
as dependencies. However, graphql depends on rxdart: ^0.22.0 and flutter_bloc depends on rxdart: ^0.23.0, which give me error:
Because flutter_bloc >=3.0.0 depends on bloc ^3.0.0 which depends on rxdart ^0.23.0, flutter_bloc >=3.0.0 requires rxdart ^0.23.0.
And because graphql 2.1.1-beta.5 depends on rxdart ^0.22.0 and no versions of graphql match >2.1.1-beta.5 <3.0.0, flutter_bloc >=3.0.0 is incompatible with graphql ^2.1.1-beta.5.
So, because com.myapp depends on both graphql ^2.1.1-beta.5 and flutter_bloc ^3.0.0, version solving failed.
My temporary fix is to downgrade flutter_bloc to ^2.1.1, which uses rxdart ^0.23.0. But if I want to use the latest and greatest version of flutter_bloc, what is the best solution?
Thanks!

You can use dependency overrides in pubspec.yaml:
dependency_overrides:
rx_dart: ^0.23.0
Note that plugins that depend on another version of the dependency you override can break if you do this.

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

Try this command: flutter pub upgrade --major-versions

Related

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:
YetAnotherLayoutBuilder expects analyzer in version >=3.0.0 and <4.0.0
hive_generator expects analyzer in version >=1.0.0 and <4.0.0
Any suggestions where I'm mistaken are gladly welcome.
Right now nether hive_generator plugin have any upgrade then this version and 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

flutter pub get error when i edit my pubspec.yaml file

I have an error when i try to add a new plugin in my pubspec.yaml
i add the plugin : easy_localization: ^3.0.0
And i have this error message :
Because flutter_launcher_icons >=0.7.0 <0.9.0 depends on args ^1.5.0 and easy_localization >=3.0.0-nullsafety depends on args ^2.0.0, flutter_launcher_icons >=0.7.0 <0.9.0 is incompatible with easy_localization >=3.0.0-nullsafety.
So, because gameapp depends on both easy_localization ^3.0.0 and flutter_launcher_icons ^0.8.0, version solving failed.
pub get failed (1; So, because gameapp depends on both easy_localization ^3.0.0 and flutter_launcher_icons ^0.8.0, version solving failed.)
Could you try adding,
flutter_launcher_icons: ^0.9.0
args: ^2.0.0
easy_localization: ^3.0.0-nullsafety
to your pubspec.yaml and try saving it again to reload the packages?
The problem is: The library version you want to use is newer than Flutter, and there are two solutions
1: Go to the library website and click on the version and install an old library, for example (easy_localization: ^ 2.3.3)
2: Install the latest version of Flutter. Flutter2

Flutter dependencies problems after upgrade

My code was working without problem. After upgrading flutter, pug get is giving error:
But when I set intl to intl 0.17.0 , I got another error
How can I solve this. Is it possible to go back in the old version of flutter? Thanks
The best way would be just remove the version from the dependencies which are causing error. And then run pub get it will automatically take the best version combination.
For example replace :-
intl: ^0.17.0
with
intl:
You can try overriding the dependencies with:
dependencies:
...
dependency_overrides:
# intl: any
intl: ^0.17.0-nullsafety.2
Try overriding with specific version to limit the problem.

How to resolve version solving failed in flutter

Because flutter_bloc: 0.21.0 depends on provider: ^3.0.0 and no versions of flutter_bloc match: >0.21.0 <0.22.0, flutter_bloc: ^0.21.0 requires provider: ^3.0.0.
So, because it tells_me that it depends on both provider: ^4.1.2 and flutter_bloc: ^0.21.0, version solving failed.
pub get failed (1; So, because tellz_me depends on both provider ^4.1.2 and flutter_bloc ^0.21.0, version solving failed.)
you need to use dependency override.
this code is from my project, so path provider was the problem, you need to find the package that makes. the conflict and put it inside the dependency_overrides
this will fix your problem.
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
file_picker: ^3.0.0
hive: ^2.0.0
hive_flutter: ^1.0.0
dependency_overrides:
path_provider: 2.0.1
See this:
https://stackoverflow.com/a/67517680/13500457
And how to update the dependencies automatically:
https://stackoverflow.com/a/66759292/13500457
I would suggest you to remove all dependencies and run pub get and add the dependencies using the command method, not by copy pasting. See this or mentioned above:
https://stackoverflow.com/a/67517680/13500457
I hope it helps, happy coding!

"Please upgrade your dependency to build_web_compilers: ">=2.0.0", but it already is

I have an AngularDart-based web project. When I'm try webdev serve, I get this:
[SEVERE] Support for dartdevc in build_web_compilers < 2.0.0 has been removed.
Please upgrade your dependency to:
dev_dependencies:
build_web_compilers: ">=2.0.0"
[SEVERE] Exception: dartdevc is no longer supported by this version
However, I already have the dependency set to "2.0.0 and newer". Here is my pubspec.yaml file:
name: myproject
description: My Description
environment:
sdk: '>=2.3.3 <3.0.0'
dependencies:
angular: ^5.2.0
angular_components: ^0.13.0
dev_dependencies:
angular_test: ^2.2.0
build_runner: ^1.5.0
build_test: ^0.10.3
build_web_compilers: ^2.0.0
pedantic: ^1.0.0
test: ^1.5.1
I tried pub get, pub upgrade, pub activate global webdev, even pub cache repair.
In general, I seem to have problems with dependencies when creating AngularDart projects, even when I use versions from the Dart docs. Is there a magic way to know exactly which version numbers to use?
Try deleting your .dart_tool directory, rerun pub get and try again.
That directory is where dart stores all of the dependencies and artifacts of the build process. Sometimes it can get in an odd state.
Whenever your Dart build is misbehaving in ways that defy explanation, it is good practice to delete the .dart_tool directory first and build clean to see if that fixes it.