Because every version of flutter_test from sdk depends on... flutter_test from sdk is forbidden, version solving failed - flutter

I'm having this issue when I've added http dependency in my flutter project. Can anyone please help me with it?

If you get the message:
Because every version of flutter_test from sdk depends on...
It means flutter_test depends on a dependency with version lower than you specified in another dependency.
To solve this, open pubspec.yaml, and remove the version number of the problem dependency:
Example:
Change
archive: ^2.0.13 --> remove this number
To:
archive:

You have provided or trying to use http: ^0.12.0 dependency on implementing API calls in pubspec.yaml file but flutter_test will require http: ^0.11.3+17. That's why it fails. Please replace
dependencies:
flutter:
sdk: flutter
http: ^0.12.0
with
dependencies:
flutter:
sdk: flutter
http: ^0.11.3
Hope it will help you out.

In my case, I somehow deleted sdk: flutter:
dependencies:
flutter:
sdk: flutter

I was facing a similar error. I solved it by removing all the version numbers from the dependencies: section in pubspec.yaml.
So, if my pubspec.yaml looked like this before:
dependencies:
freezed_annotation: ^0.14.3
I changed it to this:
dependencies:
freezed_annotation:
I'm assuming this fetches the latest "possible" version of each package.

Can you please provide the dependencies in your pubspec.yaml? It looks like your app depends on at least http 0.12.0 but flutter_test specifically requires http 0.11.3+17 (an older version) which makes it fail.

If your app doesn't have too many dependencies that could broke, you can try to upgrade your Flutter version: flutter upgrade.
It most probably will fix this problem. But always be sure to understand that your app might break at unexpected places.
So you're fine if:
either you're doing it for small app
or it's big app at work and it has extensive tests that will tell you something has broken
if big app without tests, be sure to test every important place of the app, where dependencies are being used

Try to change the dependency version that you were added in your pubspec.yaml file
don't use the current or latest version try some previous versions of dependency.
for ex - if you are using latest sqflite version then chnage to previous version of that and then re-run your whole project.

In my case IDE referred to an an older version of dart because of fvm. Seems like 'run' button called fvm flutter run, but not flutter run as I expected. After I deleted fvm folder from the project the problem has gone.

Change depending attributes version inside pubspec.yaml
if it says depands on http *** than change http version
or if it says depands on collection *** than change collection version.

Related

Conflict between dependencies when adding a new one

These were my dependencies in my pubspec.yaml:
dependencies:
...
image_picker: ^0.8.4+2
...
And everything worked fine, but now I added this:
dependencies:
...
image_picker: ^0.8.4+2
...
image_editor_pro: ^1.1.8
And running pub get I have this error:
Because image_editor_pro >=1.1.0 depends on image_picker ^0.7.4 and provauth depends on image_picker ^0.8.4+2, image_editor_pro >=1.1.0 is forbidden.
So, because provauth depends on image_editor_pro ^1.1.8, version solving failed.
pub get failed (1; So, because provauth depends on image_editor_pro ^1.1.8, version solving failed.)
I tried downgrading my version of image_picker but I get a new error:
Cannot open file, path = 'C:\Users\loren\flutter.pub-cache_temp\dir60565baa\test\fixtures\invalid\n_structure_<.>.json' (OS Error: Syntax of the name of the file, of the directory or of volume is not correct (This is my bad translation of the error).
, errno = 123)
pub get failed (66; , errno = 123))
What can I do to solve and use both the dependencies?
You can try to override the dependency so only one version is used for your project. Something like this:
name: your_app
dependencies:
image_picker: ^0.8.4+2
image_editor_pro: ^1.1.8
dependency_overrides:
image_picker: '0.8.4+2' # Use only this version for all the code depended on image picker
But you need to thoroughly tested the library that depends on the overrided dependency to check if it not introducing you a new error.
See https://dart.dev/tools/pub/dependencies#dependency-overrides
Seems like there is a conflict with image_editor_pro because the package is old.
It is better to look for another updated package with null safety, like image_editor 1.0.2, this won't have conflictions with image_picker 0.8.4+1.
And if you are willing to downgrade. ## Downgrading is a pain
You might need to downgrade the other dependencies as well. which might lead to Downgrading the Dart version.
After downgrading execute this command:
flutter clean
Then delete pubspec.lock file.
If a conflict between dependencies occurs, the simplest solution is to remove the version numbers of the two dependencies and then replace them with 'any' without the quotes in front of it. Then run pub get.
Hope you can help

Flutter: build runner throws a precompile error

I am using analyser 1.7.1. The latest build_runner build command generates the following error.
flutter packages pub run build_runner build Failed to precompile
build_runner:build_runner:
../../../sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.1/lib/src/error/best_practices_verifier.dart:1998:14:
Error: A non-null value must be returned since the return type
'String' doesn't allow null. String get displayString {
The usual flutter clean and pub cache repair commands don't seem to be fixing the problem, and displayString doesn't appear anywhere in my codebase.
There's an issue open 9 days ago. Here's the key part:
Right now, the current state of affairs is that:
package:analyzer 1.7.0 requires package:meta ^1.4.0
package:analyzer 1.7.1 has the same contents as 1.7.0, but requires package:meta ^1.3.0
Flutter stable pins package:meta to 1.3.0
I'm uncertain how we're running into the exceptions above - the two most recent versions of analyzer are pretty explicit about which version of meta they need.
#edlman do you have any dependency_overrides in your pubspec?
you're right, I'm using 3rd party pkgs which depend on meta 1.4.0 so I put it to dependency_overrides to solve the collision. It didn't come to my mind it cause such a problem.
I've changed the override to 1.3.0, it works fine, no problem yet
So I'd suggest checking whether or not there's a dependency_overrides in your pubspec, too.
It's a problem with analyser 1.7.1.
Add
dependency_overrides:
analyzer: 1.7.0
to pubspec.yaml.
There are more details available in raina77ow's answer.

How to set dependencies in the right way in pubspec.yaml in Flutter

Here are a few dependency examples from my pubspec.yaml file in my Flutter project.
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.4
firebase_core_web: ^0.2.1
firebase_crashlytics: "^0.2.4"
firebase_analytics: "^6.3.0"
I just followed installation guidelines when installing each of them. As seen, some dependencies have the version number in "..." while others don't.
It seems to be working in both ways but I wonder what the right way of doing it. Should I always put the version number into "..." ?
The best way to do this is:
flutter pub add form_field_validator
where "form_field_validator" is the name of dependency
Have a look why it is a best method:
It automatically adjusts all of the the dependencies
So you don't get "version solving failed" error like this showing below:
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.
https://pub.dev/packages/form_field_validator/install
has both methods copy and paste the given command in your project directory
See below image:
Thank you I hope it clears everything, happy coding!
You can provide version numbers with and without quotes. The quotes are used for providing range constraints on dependencies like this:
dependencies:
url_launcher: '>=5.4.0 <6.0.0'
So that's why both options work. If you are not using ranges you can omit the quotes but it comes down to personal/team preference. See the Flutter documentation for more information on using packages.
If you don't put any number or version number, it takes the latest version.
When creating new projects, it will work good. However if you are re-using codes from other projects, you might want to use the exact same version of the dependencies, hence you define them.

Dart 2.6 and Flutter, Upgrading Dependency

Using Flutter, I am trying to update my dart dependency 2.6.0 but I get an error
Because *project_name* requires SDK version >=2.6.0 <3.0.0, version solving failed.
pub get failed (1)
exit code 1
I want to use the new features that dart offers, such as Extension Methods. How could I go about upgrading my dependency? I have installed the newest stable version of dart on my computer, but regardless I still get that error.
A couple of things that might help:
From this issue, you can try ensuring that you've updated enviroment in your pubspec.yaml file like so:
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Another thing that might help is just double checking the steps in this post or on the dart installation page to ensure that you've updated to the latest version correctly.

How to determine the tag to Downgrade flutter from 2.0? Cannot build project anymore

I just updated my flutter and my project is not building anymore. I am getting the following error
Because project depends on progress_hud >=0.1.1 which requires SDK
version >=1.23.0 <2.0.0, version solving failed.
pub upgrade failed (1)
Now I read this link here which states that I should checkout that specific Tag. How do I know which Tag is associated with which branch ? Essentially I would like anything closer less than 2.0. Preferably 1.9 or something like that. How do I determine which tag that is?
Don't downgrade your Dart version, there is an issue with that package, it doesn't have the constraints updated : https://github.com/rcpassos/progress_hud/blob/master/pubspec.yaml
As you can see these constraints:
environment:
sdk: ">=1.23.0 <2.0.0"
Doesn't allow to build your app, you have two options:
wait for the owner to update the constraints
Use a fork from another user with the constraints updated, like
this:
Instead of this :
dependencies:
progress_hud: ^1.0.0
Use this:
dependencies:
progress_hud:
git: https://github.com/LampeMW/progress_hud/
Don't Downgrade Flutter. Instead add following tags in
pubspec.yaml
dependency_overrides:
shared_preferences: ">=0.5.12+4"
place your problematic packages lower versions.