Anatomy of pubspec.yaml
Declare metadata, dependencies, and constraints.
Anatomy of pubspec.yaml is a free Dart Academy lesson on CoddyKit — lesson 1 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.
Meet pubspec.yaml
Every Dart project has a pubspec.yaml at its root. It is the manifest that describes your project and lists everything it depends on. 📄
Why YAML
Dart uses YAML here because it is human-readable: indentation shows structure, and you write keys followed by a colon and a value. No braces needed.
name: my_app
version: 1.0.0The name Field
The name field is required. It must be lowercase with underscores, and it becomes the identifier other code uses to import your package.
name: weather_clientDescription and Version
Add a short description so people know what your package does, plus a version that follows the major.minor.patch format like 1.2.0.
description: A tiny weather client.
version: 1.2.0The environment Key
The environment key states which Dart SDK versions your project supports. Tools refuse to run if your SDK falls outside this range.
environment:
sdk: ^3.0.0Runtime dependencies
The dependencies section lists packages your code needs at runtime. Each entry is a package name mapped to a version constraint.
dependencies:
http: ^1.2.0dev_dependencies
Use dev_dependencies for tools you only need while building, like test or lint packages. They are not shipped to people who use your package.
dev_dependencies:
test: ^1.24.0Caret Version Constraints
A caret like ^1.2.0 means any version from 1.2.0 up to but not including 2.0.0. It lets you accept safe, compatible updates.
http: ^1.2.0Indentation Matters
YAML uses spaces, never tabs, to show nesting. A misaligned key breaks the file, so keep two-space indentation consistent throughout.
dependencies:
http: ^1.2.0Other Useful Fields
You can also add homepage, repository, and publish_to fields. They give users links and let you keep a package private when needed.
homepage: https://example.com
publish_to: noneWhere pub Reads It
When you run pub commands, the tool reads pubspec.yaml first to learn your dependencies, then fetches and resolves everything for you. 🔧
Quick Check
Where do you put packages you only need while developing?
Recap
You learned that pubspec.yaml names your project, sets the SDK range, and lists runtime and dev dependencies. It is the heart of every Dart project. 🎉
Frequently asked questions
Is the “Anatomy of pubspec.yaml” lesson free?
Yes — the full text of “Anatomy of pubspec.yaml” 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 “Anatomy of pubspec.yaml”?
Declare metadata, dependencies, and constraints. 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 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Anatomy of pubspec.yaml” 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.