Dart: Error: Couldn't resolve the package 'x' in 'package:x/x.dart'
Code imports a package that is not in pubspec.yaml or pub get has not been run since adding it.
Error: Couldn't resolve the package in package:Target of URI doesn't exist: 'package:Couldn't resolve the package 'http' in 'package:http/http.dart'Not found: 'package:x/x.dart'Could not resolve the package Meaning
Add the dependency (flutter pub add x), run flutter pub get, and restart the IDE/analysis server. Also check the import path spelling and that the package name in the import matches the package's name: (dashes vs underscores).
Common causes
- Dependency missing from pubspec.yaml
- pub get not run
- Typo in package name or import path
- Package named differently than expected
- Stale .dart_tool/package_config.json
⚡ Quick fix
flutter pub add package_nameflutter pub getand restart the Dart analysis server- Delete
.dart_tooland re-run pub get
Detailed fix by platform
Flutter
flutter pub add http && flutter pub get
How to diagnose
- Pubspec — Dependency listed?
- Pub get — Run?
- Name — Spelled correctly?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Bad state: No element Dart: Bad state: No element — .first, .last or .single on an empty list
- Bad state: Stream has already been listened to Dart: Bad state: Stream has already been listened to
- FormatException: Unexpected character Dart: FormatException: Unexpected character (at character 1) <!DOCTYPE html> — jsonDecode of an HTML page
Most viewed in Flutter / Dart
- setState() called after dispose() Flutter: setState() called after dispose(): _MyState#1a2b3 (lifecycle state: defunct, not mounted)
- A RenderFlex overflowed Flutter: A RenderFlex overflowed by x pixels on the right/bottom
- SocketException: Failed host lookup Flutter: Unhandled Exception: SocketException: Failed host lookup: 'api.example.com' (OS Error: No address associated with hostname, errno = 7)
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026