Maaz Zindani

Loading the index…

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

A new package does not show up after flutter pub get

ErrorGot socket error trying to find package

Short answer

After you add a package, run flutter pub get and check its output. Three things go wrong: two packages need incompatible versions of a shared dependency, pub cannot reach pub.dev because of a proxy or firewall, or a package with native code needs a full stop and rebuild instead of hot reload.

  • Applies to Flutter 3.35, Dart 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Add the package with the command, not by hand, then read the whole output of the install.

    flutter pub add english_words
  2. 2Match what you see, then jump to its fix

    1. 1pub get stops with a version conflict instead of finishingTwo packages need incompatible versions of one dependencyFix
    2. 2Got socket error trying to find package ... at https://pub.dev.pub cannot reach pub.devFix
    3. 3MissingPluginException when the plugin is first usedThe package has native code and the app was only hot reloadedFix
    4. 4The editor reports the package or import as not foundpub get was never run, or the import does not match the package nameFix

What does the error look like?

  • Got socket error trying to find package
  • pub get failed (server unavailable) -- attempting retry 1 in 1 second...
  • MissingPluginException

Cause 1 of 4

Two packages need incompatible versions of one dependency

1Check

Use version ranges (caret syntax) in pubspec.yaml. An exact pin such as image_picker: '5.4.3' allows only one version and collides easily.

cat pubspec.yaml

2Fix

Widen the pins to ranges and run pub upgrade. As a last resort, force a version with dependency_overrides.

flutter pub upgrade

# pubspec.yaml, last resort only
dependency_overrides:
  url_launcher: '5.4.0'

3Verify

pub get finishes and pubspec.lock lists the resolved versions.

flutter pub get

Confirmed by docs.flutter.dev

Did this fix it?

Cause 2 of 4

pub cannot reach pub.dev

1Check

pub get retries after a socket error. A firewall, security software or a proxy is blocking dart.

curl -I https://pub.dev

2Fix

Behind a proxy, set the https_proxy variable, which pub honours. Add a user name and password in the form username:password@hostname:port if the proxy needs them. Allow dart and pub.dev in security software.

export https_proxy=hostname:port
flutter pub get

3Verify

pub get downloads the package without a retry message.

flutter pub get

Confirmed by dart.dev

Did this fix it?

Cause 3 of 4

The package has native code and the app was only hot reloaded

1Check

Hot reload and hot restart update Dart code only. A plugin with Kotlin, Java, Swift or Objective-C code is not in the running app yet.

flutter pub deps | grep <package name>

2Fix

Stop the app and run it again.

flutter run

3Verify

The plugin call works after the full restart.

flutter logs

Confirmed by docs.flutter.dev

Did this fix it?

Cause 4 of 4

pub get was never run, or the import does not match the package name

1Check

Editing pubspec.yaml alone does not install anything. Compare the import with the name under dependencies.

grep -n "english_words" pubspec.yaml pubspec.lock

2Fix

Run pub get, then import with the package name exactly as written in pubspec.yaml.

flutter pub get
# in Dart code
import 'package:english_words/english_words.dart';

3Verify

The import no longer shows an error.

flutter analyze

Confirmed by docs.flutter.dev

Did this fix it?

How do I stop it coming back?

  • Add packages with flutter pub add, which edits pubspec.yaml and installs in one step.
  • Use caret version ranges, not exact pins, so pub has room to resolve conflicts.
  • Commit pubspec.lock for an app, so everyone gets the same versions.
  • Use dart pub get --enforce-lockfile in CI to catch a lockfile that does not match pubspec.yaml.

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.