# Dart: Error: Couldn't resolve the package 'x' in 'package:x/x.dart'

**Code:** `Error: Couldn't resolve the package` · **Category:** Flutter / Dart · **Seen on:** Flutter

Code imports a package that is not in `pubspec.yaml` or `pub get` has not been run since adding it.

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

1. `flutter pub add package_name`
2. `flutter pub get` and restart the Dart analysis server
3. Delete `.dart_tool` and re-run pub get

## Detailed fix by platform

### Flutter

1. `flutter pub add http && flutter pub get`

## How to diagnose

1. **Pubspec** — Dependency listed?
2. **Pub get** — Run?
3. **Name** — Spelled correctly?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/flutter/couldnt-resolve-package)
