A new package does not show up after flutter pub get
Got socket error trying to find packageShort 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.
Fix it fast
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_words2Match what you see, then jump to its fix
- 1
pub get stops with a version conflict instead of finishingTwo packages need incompatible versions of one dependencyFix - 2
Got socket error trying to find package ... at https://pub.dev.pub cannot reach pub.devFix - 3
MissingPluginException when the plugin is first usedThe package has native code and the app was only hot reloadedFix - 4
The editor reports the package or import as not foundpub get was never run, or the import does not match the package nameFix
- 1
What does the error look like?
Got socket error trying to find packagepub 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.yaml2Fix
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 getConfirmed by docs.flutter.dev
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.dev2Fix
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 get3Verify
pub get downloads the package without a retry message.
flutter pub getConfirmed by dart.dev
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 run3Verify
The plugin call works after the full restart.
flutter logsConfirmed by docs.flutter.dev
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.lock2Fix
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 analyzeConfirmed by docs.flutter.dev
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:
- 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