Skip to the workspace
Pebellslearn by building
Package Managers  ›  Capstone Project

Version Constraints and the Lock File

flutter pub / dart pub 15 minA caret constraint in pubspec.yaml allows compatible versions up to the next breaking release, while pubspec.lock records the exact versions chosen so every build matches.

flutter / Version Constraints and the Lock File

Explore each scene at your own pace.

01 · The rule

The rule

Version Constraints and the Lock File

The http line in Sprout's pubspec.yaml says ^1.2.0, yet your machine is using version 1.2.2. A teammate's might pick something else next month. To reason about that, you need to read two things: the constraint you wrote, and the lock file pub wrote for you.

The rule

The caret allows everything up to the next breaking version; the lock file pins one.

Dart packages use semantic versioning: major.minor.patch.

  • Patch (1.2.2): bug fixes.
  • Minor (1.3.0): new features, nothing removed.
  • Major (2.0.0): may break existing code.

A caret constraint accepts any version that should be compatible:

Constraint Allows Stops before
^1.2.0 1.2.0, 1.2.9, 1.9.4 2.0.0
^0.4.1 0.4.1, 0.4.7 0.5.0

For packages still below 1.0, the minor number plays the role of the breaking one, so the caret stops at the next minor.

Other forms exist, such as an exact 1.2.0 or a range '>=1.2.0 <1.5.0', but the caret is the normal choice and what pub add writes.

pubspec.lock records the single version pub actually chose for every package, including the packages your packages depend on:

  http:
    dependency: "direct main"
    source: hosted
    version: "1.2.2"

flutter pub get reuses those locked versions. Only flutter pub upgrade (or changing a constraint) chooses new ones.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.