Flutter pubspec dependency conflict - flutter

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

Related

Flutter_Stripe Package not compatible with purchases_flutter ?- Result of updating to Flutter 3.0

I am getting the following version resolving error and I am wondering if anybody has an idea for a workaround?
Pub Spec
purchases_flutter: ^3.10.0
flutter_stripe: ^3.3.0
freezed_annotation: ^2.1.0
ERROR:
Because purchases_flutter 3.10.0 depends on freezed_annotation ^1.1.0 and no versions of purchases_flutter match >3.10.0 <4.0.0, purchases_flutter ^3.10.0 requires freezed_annotation ^1.1.0.
So, because multiculturalapp depends on both purchases_flutter ^3.10.0 and freezed_annotation ^2.1.0, version solving failed.
pub get failed (1; So, because multiculturalapp depends on both purchases_flutter ^3.10.0 and freezed_annotation ^2.1.0, version solving failed.)
You're seeing the error because purchases_flutter depends on version ^1.1.0 of freezed_annotation, which means it needs a version that is at least 1.1.0, but lower than 2.X.X. However, you're specifying freezed_annotation: ^2.1.0, which means you're saying you need 2.1.0 or higher, but lower than 3.X.X.
There's no way to resolve that conflict, so you see the error.
Can you switch to freezed_annotation: ^1.1.0?

depends on both floor_generator ^1.2.0 and retrofit_generator ^4.0.1, version solving failed

I am using retrofit_generator and floor_generator in my application.
retrofit_generator: ^4.0.1
floor_generator: ^1.2.0
When I am trying to run flutter packages pub run build_runner build getting this error:
Because no versions of retrofit_generator match >4.0.1 <5.0.0 and retrofit_generator 4.0.1 depends on analyzer ^3.0.0, re
trofit_generator ^4.0.1 requires analyzer ^3.0.0.
And because floor_generator >=1.2.0 depends on analyzer ^2.2.0, retrofit_generator ^4.0.1 is incompatible with floor_gene
rator >=1.2.0.
So, because my_flutter_app depends on both floor_generator ^1.2.0 and retrofit_generator ^4.0.1, version solving failed.
Running "flutter pub get" in my_flutter_app...
pub get failed (1; So, because my_flutter_app depends on both floor_generator ^1.2.0 and retrofit_generator ^4.0.1,
version solving failed.)
Also, tried to add analyzer: ^3.0.0 in dev_dependencies then:
Because floor_generator >=1.2.0 depends on analyzer ^2.2.0 and my_flutter_app depends on analyzer ^3.0.0, floor_generator >=1.2.0 is forbidden.
So, because my_flutter_app depends on floor_generator ^1.2.0, version solving failed.
pub get failed (1; So, because my_flutter_app depends on floor_generator ^1.2.0, version solving failed.)
exit code 1
How can we use both without errors?
Checking the retrofit_generator CHANGELOG, you will see there was a breaking change on version 4.0.0 making the library depend on version 3.0.0 but floor_generator hasn't been updated for the last 7 months and it depends on older version of analyzer.
Possible solution would be to downgrade retrofit_generator in a version prior to the breaking change, or wait till the publisher of floor_generator updates its dependencies.
They said on there github on issue:
It looks like the current master already supports analyzer <5.0.0 but
it's not on pub.dev yet because of a failed test because the pub
command can't be found.
check this link the issue
so thanks for this at least now we can use the git url until you publish it on pub.dev .
use:
retrofit_generator:
git:
url: https://github.com/trevorwang/retrofit.dart.git/
ref: master
path: generator
instead of
retrofit_generator: ^4.0.1

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

Dart Packages: Dependency conflicts

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

version solving failed when try get pubspec.yaml

I facing issue that show up to me that message when Trying to get packages
Running "flutter pub get" in stok_app_a...
Because no versions of in_app_purchase match >0.2.2+4 <0.3.0 and in_app_purchase 0.2.2+4 depends on json_annotation ^2.0.0, in_app_purchase ^0.2.2+4 requires json_annotation ^2.0.0.
And because every version of speech_to_text depends on json_annotation
^3.0.0, in_app_purchase ^0.2.2+4 is incompatible with speech_to_text.
So, because stok_app_a depends on both speech_to_text ^0.7.0 and
in_app_purchase ^0.2.2+4, version solving failed. pub get failed (1;
So, because stok_app_a depends on both speech_to_text ^0.7.0 and
in_app_purchase ^0.2.2+4, version solving failed.) exit code 1
I solved this issue by assignment dependency_overrides in pubspec.yaml file like that
dependency_overrides:
json_annotation: ^2.0.0
to override the json_annotation 2.0.0