Sub topic 10
Finding Outdated Packages and Upgrading
Assume that you know basic Dart syntax, have a Flutter project, can edit YAML, and can run Flutter commands in a terminal. This chapter focuses on finding old packages and upgrading them safely.
Inspecting outdated packages
Run this command from your project directory:
flutter pub outdatedThe command compares the versions in your project with versions available from the package repository. Its table commonly includes these columns:
| Column | Meaning |
|---|---|
| Current | The version recorded in `pubspec.lock` |
| Upgradable | The newest version allowed by your current `pubspec.yaml` constraints |
| Resolvable | The newest version that can be selected after dependency resolution |
| Latest | The newest published version |
For example, if Current is 1.4.0, Upgradable is 1.6.2, and Latest is 2.0.0, your current constraint may allow the 1.x update but exclude the breaking 2.0.0 release.
The Current value comes from the lockfile. The lockfile records the exact versions selected for this project, including transitive dependencies. A transitive dependency is a package that another package needs.
Use the non-transitive option when you want to focus on packages listed directly in your own pubspec.yaml:
flutter pub outdated --no-transitiveUpgrading within existing constraints
The safest first step is:
flutter pub upgradeThis asks Pub to find newer versions that still satisfy the constraints in pubspec.yaml. It normally updates pubspec.lock, but it does not broaden your declared version ranges.
For example, this constraint permits compatible 1.x releases:
dependencies:
http: ^1.2.0The caret means that Pub may select a version from 1.2.0 up to, but not including, 2.0.0. Running flutter pub upgrade can therefore move http from 1.2.0 to a newer compatible 1.x version.
After upgrading, run the project's checks:
flutter pub upgrade
flutter analyze
flutter test
flutter runflutter analyze checks Dart code for errors and warnings. flutter test runs automated tests. Running the app can reveal platform or behavior changes that static checks do not detect.
Upgrading to newer major versions
If Latest is outside your current constraints, inspect the package's migration notes first. Then you can ask Pub to update direct dependency constraints:
flutter pub upgrade --major-versionsReview the changes to pubspec.yaml and pubspec.lock before committing them. Upgrade one related group at a time when possible. This makes a failure easier to identify and keeps the change reversible.
The upgrade process follows this path:
Handling an upgrade failure
When resolution fails, read the first useful conflict in the error output. It usually names two packages whose constraints cannot be satisfied together. Check whether a newer release of one package supports the required version of the other.
Do not immediately use a dependency override to hide the conflict. An override can produce a combination that the package authors did not test. Prefer upgrading the conflicting direct dependency, choosing a compatible version, or waiting for a compatible release.
Exercise
Your project shows Current: 1.2.0, Upgradable: 1.5.0, and Latest: 2.0.0 for a package. Which command should you try first, and why?
Show answer
Run flutter pub upgrade. It can select version 1.5.0 without changing the existing constraint. Review the changelog before considering flutter pub upgrade --major-versions for version 2.0.0.