Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

flutter pub get fails and no packages are downloaded

Errorpub get failed

Short 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.

  • Applies to Flutter 3.50 stable, Dart 3.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 -v
  2. 2Match what you see, then jump to its fix

    1. 1Got socket error trying to find package ... at https://pub.dev.pub.dev cannot be reached (offline, ISP, or security software)Fix
    2. 2Network works in a browser, but pub get cannot connect from the office networkA corporate proxy is not used by pubFix
    3. 3Solving fails and the message lists two packages whose version ranges do not meetVersion constraints cannot all be satisfiedFix
    4. 4pub get fails only in a pipeline that passes --enforce-lockfileThe lockfile does not match pubspec.yaml (CI with --enforce-lockfile)Fix

What does the error look like?

  • pub get failed
  • Got socket error trying to find package
  • pub 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 1

2Fix

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 get

3Verify

pub get completes and writes pubspec.lock.

ls -l pubspec.lock

Confirmed by dart.dev

Did this fix it?

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 proxy

2Fix

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 get

3Verify

pub get now downloads packages.

flutter pub get

Confirmed by dart.dev

Did this fix it?

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 outdated

2Fix

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 --tighten

3Verify

Resolution succeeds and the lockfile updates.

flutter pub get

Confirmed by dart.dev

Did this fix it?

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.lock

2Fix

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.lock

3Verify

pub get passes, and the CI run with the lockfile enforced passes too.

flutter pub get

Confirmed by dart.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.