flutter pub get fails: version solving failed because of flutter_test from sdk
Because every version of flutter_test from sdk depends onShort answer
The Flutter SDK pins a few packages to exact versions, and flutter_test depends on them. If your pubspec, or a package you use, asks for a version outside that pin, pub cannot solve and blames flutter_test from sdk. Widen the constraint, upgrade the blocking package, or as a short-term step use dependency_overrides.
Fix it fast
1Find out which cause you have
Read the full pub message, not only the last line. It names the package whose version range clashes with the one the SDK pins. Then print the dependency tree to see who asks for that package.
flutter pub get dart pub deps --style=compact2Match what you see, then jump to its fix
- 1
The message names a package you list directly in pubspec.yaml, for example path, collection, characters or metaYour own constraint excludes the version Flutter pinsFix - 2
The message names a package that is not in your pubspec.yaml, and a chain such as 'foo depends on bar >=2.0.0'A dependency of a dependency does not allow the pinned versionFix - 3
The problem shows only in one tool (CI job, script, or plain dart pub get), while flutter pub get workspub runs without the Flutter SDKFix
- 1
What does the error look like?
Because every version of flutter_test from sdk depends onflutter_test from sdk is forbiddenversion solving failed
Cause 1 of 3
Your own constraint excludes the version Flutter pins
1Check
Compare the range you wrote with the range pub reports. Flutter pins some packages (characters, collection and path are named examples), and your constraint must include the pinned version.
grep -n "path:\|collection:\|characters:\|meta:" pubspec.yaml
flutter --version2Fix
Widen the constraint so it includes the pinned version, for example from a narrow range to a caret range, then run pub again.
dependencies:
path: ^1.8.03Verify
pub resolves and writes pubspec.lock.
flutter pub getConfirmed by github.com
Cause 2 of 3
A dependency of a dependency does not allow the pinned version
1Check
Find which of your direct dependencies pulls in that package, and whether a newer release of it supports the pinned version.
dart pub deps --style=list
dart pub outdated2Fix
Upgrade the direct dependency to a release that supports the pinned version, or ask its maintainers for one. Until it exists, a dependency override is a short-term way out; remove it as soon as the package is fixed.
dependency_overrides:
path: 1.9.03Verify
pub resolves with the override removed after the upgrade.
flutter pub upgradeConfirmed by github.com
Cause 3 of 3
pub runs without the Flutter SDK
1Check
A dependency with sdk: flutter can only be satisfied when pub runs in the context of the flutter executable. Check which command your pipeline uses.
which flutter dart
grep -rn "pub get" .github ci scripts 2>/dev/null2Fix
Run flutter pub get, not dart pub get, in Flutter projects, and make sure flutter from the right SDK is on PATH.
flutter pub get3Verify
The command succeeds and pubspec.lock lists flutter_test with source sdk.
grep -n -A3 "flutter_test" pubspec.lockConfirmed by dart.dev
How do I stop it coming back?
- Use caret ranges such as ^1.8.0 for direct dependencies, not narrow bounds or single pinned versions.
- Run flutter pub outdated now and then and upgrade packages in small steps.
- Keep dependency_overrides out of committed code unless a comment explains when to remove it.
- Use flutter pub get in scripts and CI for Flutter projects.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
flutter pub get fails and no packages are downloaded
Got socket error trying to find package
Run pub get in a terminal and read the first error.
4 causes, each with a fixMobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fix