flutter pub get fails and no packages are downloaded
pub get failedShort answer
Run pub get in a terminal and read the first error. A socket or server-unavailable line means the network, a proxy or a firewall is in the way. A version-solving message means two packages ask for ranges that cannot both be met. A lockfile error appears only when --enforce-lockfile is on. Each has a different fix.
Fix it fast
1Find out which cause you have
Run it in a terminal instead of the IDE button, so you see the whole message. The first error line decides which cause below applies.
flutter pub get -v2Match what you see, then jump to its fix
- 1
Got socket error trying to find package ... at https://pub.dev.pub.dev cannot be reached (offline, ISP, or security software)Fix - 2
Network works in a browser, but pub get cannot connect from the office networkA corporate proxy is not used by pubFix - 3
Solving fails and the message lists two packages whose version ranges do not meetVersion constraints cannot all be satisfiedFix - 4
pub get fails only in a pipeline that passes --enforce-lockfileThe lockfile does not match pubspec.yaml (CI with --enforce-lockfile)Fix
- 1
What does the error look like?
pub get failedGot socket error trying to find packagepub get failed (server unavailable) -- attempting retry 1 in 1 second...
Cause 1 of 4
pub.dev cannot be reached (offline, ISP, or security software)
1Check
pub retries a few times and then fails. The documented reasons are no internet, an ISP that blocks pub.dev, or a firewall or security tool that blocks the dart process.
curl -sI https://pub.dev | head -n 12Fix
Restore the connection first. If the curl line prints nothing, test on another network. Then make sure no firewall or security software blocks the dart executable.
flutter pub get3Verify
pub get completes and writes pubspec.lock.
ls -l pubspec.lockConfirmed by dart.dev
Cause 2 of 4
A corporate proxy is not used by pub
1Check
pub does not pick up your system proxy. It reads the http_proxy and https_proxy environment variables.
env | grep -i proxy2Fix
Set https_proxy to the proxy host and port. If the proxy needs credentials, put them in front as username:password@hostname:port.
export https_proxy=hostname:port
flutter pub get3Verify
pub get now downloads packages.
flutter pub getConfirmed by dart.dev
Cause 3 of 4
Version constraints cannot all be satisfied
1Check
pub intersects every constraint on a shared package and picks the newest version inside. It fails when the ranges are disjoint, or when the overlap contains no published version. See which of your packages are behind.
flutter pub outdated2Fix
Upgrade the package that holds back the other, within what your pubspec allows. Raise the constraint if needed. Use dependency_overrides only as a temporary workaround, since it hides a real incompatibility.
flutter pub upgrade
# raise constraints to the latest versions:
flutter pub upgrade --tighten3Verify
Resolution succeeds and the lockfile updates.
flutter pub getConfirmed by dart.dev
Cause 4 of 4
The lockfile does not match pubspec.yaml (CI with --enforce-lockfile)
1Check
That flag fails when pubspec.lock is not an exact valid resolution of pubspec.yaml, or when a hosted package's content hash changed.
git status --short pubspec.yaml pubspec.lock2Fix
Resolve on your own machine without the flag, review the new pubspec.lock and commit it with the pubspec change.
flutter pub get
git add pubspec.yaml pubspec.lock3Verify
pub get passes, and the CI run with the lockfile enforced passes too.
flutter pub getConfirmed by dart.dev
How do I stop it coming back?
- Commit pubspec.lock for apps so every machine and CI run resolves the same versions.
- Use caret constraints (^1.2.3) instead of pinning exact versions without a reason.
- Run flutter pub outdated now and then so conflicts show up one package at a time.
- Run CI with --enforce-lockfile so a stale lockfile fails fast.
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
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 fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix