Sub topic 10
Finding Outdated Packages and Upgrading
This chapter covers how to see which dependencies have newer versions, how to move to them, and what can go wrong. It assumes you can read a caret constraint such as ^1.2.0, you know that pubspec.lock records the exact resolved versions, and you can run commands in a Flutter project.
Why upgrades are a separate step
Running flutter pub get does not move you to newer versions. If pubspec.lock already pins http at 1.2.0, pub get keeps 1.2.0 even when 1.2.2 exists and your constraint allows it. The lockfile makes builds repeatable, but it also means your project falls behind unless you ask for an upgrade.
Two files control what you get:
pubspec.yamlstates which versions you will accept (the constraint).pubspec.lockstates which version you actually have (the resolved version).
An upgrade can change the lockfile alone, or it can change both files. The commands below differ in which of these they touch.
Listing outdated packages with flutter pub outdated
flutter pub outdatedThe command prints a table with one row per dependency. Each row has four version columns:
| Column | Meaning |
|---|---|
| Current | The version in `pubspec.lock` right now |
| Upgradable | The highest version your current constraint in `pubspec.yaml` allows |
| Resolvable | The highest version that could be used if you also edited your constraints, given all other dependencies |
| Latest | The newest version published on pub.dev |
A typical output looks like this:
Showing outdated packages.
[*] indicates versions that are not the latest available.
Package Name Current Upgradable Resolvable Latest
direct dependencies:
http *1.1.0 *1.1.2 1.2.2 1.2.2
provider 6.1.2 6.1.2 6.1.2 6.1.2
dev_dependencies:
flutter_lints *3.0.2 *3.0.2 *3.0.2 5.0.0Read the columns from left to right to decide what to do:
- Current differs from Upgradable. A plain
flutter pub upgradewill move you. No edit topubspec.yamlis needed. - Upgradable differs from Resolvable. Your constraint is the limit. Raising the constraint, for example from
^1.1.0to^1.2.0, unlocks the newer version. - Resolvable differs from Latest. Something else blocks the newest release. Usually another package in your dependency graph requires an older version of this one, or the new release needs a newer Dart SDK than you have.
- All four match. Nothing to do.
In the example above, http can be upgraded in place to 1.1.2, and a constraint change would allow 1.2.2. flutter_lints is stuck at 3.0.2 even if you edit the constraint, because its Resolvable column also shows 3.0.2. The cause is likely your SDK version or a constraint from another package.
Useful flags
flutter pub outdated --no-dev-dependencies
flutter pub outdated --show-all
flutter pub outdated --mode=null-safety--no-dev-dependencieshides thedev_dependenciessection, which helps when you only care about what ships in your app.--show-allalso lists packages that are already up to date, and includes transitive dependencies (packages your dependencies depend on).- Transitive dependencies are normally shown only when they are outdated. You cannot upgrade them by editing your own constraints, but you can often unlock them by upgrading the direct dependency that pulls them in.
The command exits with a non-zero status only for errors, not because packages are outdated by default. You can add --exit-code style checks in continuous integration, but check flutter pub outdated --help for the flags your SDK version supports.
Upgrading within your constraints
flutter pub upgradeThis re-resolves the whole dependency graph and picks the newest versions that satisfy every constraint. It rewrites pubspec.lock and leaves pubspec.yaml untouched. Because it respects the caret ranges, it never crosses a major version boundary for a package at 1.x or higher.
You can upgrade a single package and leave the rest of the lockfile as it is:
flutter pub upgrade httpOnly http and whatever it needs to stay consistent can move. Other packages stay at their locked versions unless the solver is forced to change them.
If you want to be careful about what changed, run git diff pubspec.lock afterward. Version bumps in the lockfile are the actual record of what changed in your build.
Seeing what an upgrade would do
flutter pub upgrade --dry-runThis prints the changes without writing them. A > marks an upgraded package, a < marks a downgrade, and a + or - marks one added or removed. Use it before upgrading a project you do not want to break at the end of a working day.
Upgrading past your constraints
When Upgradable is behind Resolvable, use --major-versions:
flutter pub upgrade --major-versionsThis command edits the constraints in pubspec.yaml to allow the newest resolvable versions, then updates the lockfile. It is the only upgrade command that changes pubspec.yaml. It works across all direct dependencies at once, and you can name one package instead:
flutter pub upgrade --major-versions httpA related flag, --tighten, raises the lower bound of each constraint to the version currently resolved. For example, ^1.1.0 becomes ^1.1.2 if 1.1.2 is what you have. This stops the project from silently allowing very old versions that you have never tested.
flutter pub upgrade --tightenMajor version bumps follow semantic versioning, so they are allowed to contain breaking changes. Read the package's changelog on its pub.dev page (the Changelog tab) before accepting one. Note that for versions below 1.0.0, Dart treats a minor bump as potentially breaking: ^0.5.0 allows 0.5.x but not 0.6.0.
The upgrade workflow
Starting from a clean commit gives you a one-command undo. After an upgrade, run flutter analyze to catch removed or renamed APIs at compile time, then flutter test. Run the app on at least one real target as well. Static analysis cannot catch a plugin whose native behavior changed.
Upgrading the SDK and its packages
Flutter ships with several packages pinned to the SDK, such as flutter, flutter_test, and flutter_localizations. These use sdk: flutter and have no version of their own, so pub upgrade never changes them. They change when you run:
flutter upgradeThat command updates the Flutter SDK itself, which includes its bundled Dart SDK. After it finishes, run flutter pub get or flutter pub outdated again. A newer Dart SDK can widen what the solver is allowed to choose, so rows that were stuck at an older Resolvable version may now move.
Do not confuse the two commands. flutter upgrade changes the tool. flutter pub upgrade changes your project's packages.
Edge cases and common errors
Upgrade changes nothing
If flutter pub upgrade reports "No dependencies changed" but pub outdated shows a newer Latest, the constraint is holding you back. Look at the Upgradable and Resolvable columns, then use --major-versions or edit the constraint by hand.
Upgrade fails with a solving error
A failed upgrade prints a message that starts with "Because ... depends on ... which requires ...". It means two packages ask for incompatible versions of a third. Read the message from the bottom: the last line names the decision the solver could not make. Typical fixes are to upgrade the conflicting package together with the one that depends on it, or to hold one package back. The next chapters cover reading these messages in detail.
Lockfile drift between team members
If pubspec.lock is in .gitignore for an app, each developer can resolve different versions. For applications, commit the lockfile. For packages you publish, the convention is not to commit it, because consumers resolve their own versions.
Transitive dependency stuck on an old version
You cannot force a transitive package forward by editing your own constraints. First check which direct dependency requires it:
flutter pub deps
flutter pub deps --style=compactThen upgrade that direct dependency. Use a dependency override only as a last resort, since it bypasses the checks the solver is there to perform.
Plugin upgrades that need native work
Upgrading a plugin can require changes outside Dart. A new version may need a higher Android minSdkVersion, a newer iOS deployment target, or a changed Gradle or CocoaPods setup. If the Dart build passes but the app fails on a device, read the plugin's changelog for platform notes. A stale ios/Podfile.lock is a frequent cause on iOS, and running flutter clean followed by flutter pub get often resolves build cache problems.
Choosing how often to upgrade
| Strategy | Benefit | Cost |
|---|---|---|
| Upgrade within constraints often | Small diffs, security fixes arrive quickly | Needs a test habit |
| Run `--major-versions` on a schedule | Avoids large migrations later | Each batch needs reading changelogs |
| Upgrade only when forced | Little day-to-day work | Falls behind and makes eventual jumps risky |
A common compromise is to run flutter pub upgrade regularly, review flutter pub outdated monthly, and do major upgrades one package per commit so a regression is easy to bisect.
Exercise
Your flutter pub outdated output shows http with Current 1.1.0, Upgradable 1.1.2, Resolvable 1.2.2, and Latest 1.2.2. Which command moves you to 1.2.2, and which command moves you only to 1.1.2? Which files does each change?
Show answer
flutter pub upgrade --major-versions http moves to 1.2.2. It edits the constraint in pubspec.yaml and updates pubspec.lock. flutter pub upgrade http moves only to 1.1.2 because it respects the existing constraint, and it changes only pubspec.lock.
Exercise
A teammate runs flutter upgrade and expects it to update the provider package in your app. Why does this not happen, and what should they run instead?
Show answer
flutter upgrade updates the Flutter SDK and its bundled Dart SDK, not the packages listed in pubspec.yaml. To update provider, run flutter pub upgrade provider, or flutter pub upgrade --major-versions provider if the newer version is outside the current constraint.