0Pricing
Dart Academy · Lesson

Version Constraints and the Lockfile

Pin and resolve dependency versions.

Version Constraints and the Lockfile is a free Dart Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Constraints Exist

A version constraint tells pub which releases of a package your project accepts. It balances getting fixes with avoiding breaking changes. 🎯

http: ^1.2.0

Semantic Versioning

Dart packages follow semantic versioning: major.minor.patch. A major bump signals breaking changes, minor adds features, patch fixes bugs.

version: 2.4.1

The Caret Constraint

The caret ^1.2.0 accepts anything from 1.2.0 up to but not including 2.0.0. It is the friendly default pub uses.

http: ^1.2.0

Pinning One Version

Writing just a bare number means exactly that version, nothing else. Use it sparingly when you need a single known release.

http: 1.2.0

Range Constraints

You can spell out a range with comparison operators. This gives you fine control over both the lower and upper bounds.

http: '>=1.0.0 <2.0.0'

The any Constraint

Using any accepts every version. It is risky because a future major release could break you, so prefer a caret instead.

http: any

Meet the Lockfile

When pub resolves your dependencies, it records the exact chosen versions in pubspec.lock. This file pins what everyone actually installs.

Reproducible Builds

The lockfile guarantees reproducible builds: a teammate running pub get gets the very same versions you tested, not surprise upgrades.

Should You Commit It

For apps, commit pubspec.lock to version control. For reusable packages, leave it out so consumers resolve versions themselves.

Updating the Lockfile

Run dart pub upgrade to refresh pubspec.lock to the newest versions your constraints allow. A plain get keeps existing pins.

dart pub upgrade

Resolving Conflicts

If two packages demand incompatible versions, pub reports a conflict. You then loosen a constraint or pick compatible package versions.

Quick Check

What does the constraint ^1.2.0 allow?

Recap

You now read constraints like caret and ranges, and you know pubspec.lock pins exact versions for reproducible, conflict-free builds. 🎉

Frequently asked questions

Is the “Version Constraints and the Lockfile” lesson free?

Yes — the full text of “Version Constraints and the Lockfile” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.

What will I learn in “Version Constraints and the Lockfile”?

Pin and resolve dependency versions. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Dart Academy?

No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Version Constraints and the Lockfile” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Dart Academy lesson?

Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Anatomy of pubspec.yaml
  2. Adding Dependencies With dart pub
  3. Imports, Exports, and Libraries
  4. Version Constraints and the Lockfile
← Back to Dart Academy