Dart cheat sheet
A scannable Dart reference: 7 short snippets across 5 topics, each linking back to the lesson it came from.
At a glance
| Topic | What it covers | |
|---|---|---|
| Isolates, compilation and packaging | Each isolate runs on a single thread with two queues: microtasks, which drain completely before the loop continues, and | lesson |
| Packages, pubspec and project layout | Write a pubspec, manage version constraints and lock files, structure a package, and know what publishing requires | lesson |
| Testing Dart code | expectLater returns a Future that must be awaited, which is what makes completion and emits reliable. Forgetting the | lesson |
| Command-line tools: args, stdin and exit codes | A tool that reports a failure in its log and still exits 0 is unusable in a pipeline. The exit code is the interface | lesson |
| From Dart to Flutter | The single most common Flutter bug is creating a Future or a controller inside build. Every rebuild starts a new | lesson |
Quick snippets
Isolates, compilation and packaging
Packaging and compilation
# pubspec.yaml
name: my_tool
description: A small command line tool.
version: 0.1.0
environment:
sdk: ^3.5.0
dependencies:
http: ^1.2.0
dev_dependencies:
test: ^1.25.0
lints: ^4.0.0
Packaging and compilation
dart pub get # resolve pubspec.lock
dart pub add http # add and record a dependency
dart pub upgrade --major-versions # move constraints forward
dart analyze # static checks
dart format . # rewrite to canonical style
dart test # run the test/ directory
dart run bin/my_tool.dart # JIT, fast startup during development
dart compile exe bin/my_tool.dart -o build/my_tool # native AOT
dart compile js web/main.dart -o build/main.js # for the browser
dart pub publish --dry-run # check before publishingFull lesson: Isolates, compilation and packaging →
Packages, pubspec and project layout
The pubspec
dart pub get # resolve and write pubspec.lock
dart pub upgrade # move to the newest allowed versions
dart pub upgrade --major-versions
dart pub outdated # what is behind, and whether it is safe to move
dart pub add http # edit the pubspec and resolve
dart pub deps --style=compact
dart pub publish --dry-run # validate before publishing
dart pub cache repair # fix a corrupted package cache
Layout and visibility
// lib/shop_core.dart — the public surface
/// Pricing rules and domain models for the shop.
library;
export 'src/money.dart' show Money;
export 'src/pricing.dart' show PricingRule, applyRules;
// src/internal/rounding.dart is deliberately not exported.
// Because everything outside lib/src is importable by convention,
// dart's linter warns when a consumer imports package:shop_core/src/...
// The src/ directory is the community agreement for "private to this package".Full lesson: Packages, pubspec and project layout →
Testing Dart code
Fakes, mocks and integration
dart test
dart test test/money_test.dart
dart test --name "currency"
dart test --coverage=coverage
dart run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
dart test -p vm,chrome # run on several platformsFull lesson: Testing Dart code →
Command-line tools: args, stdin and exit codes
Compiling and shipping an executable
# to publish the tool so others can run it with dart pub global activate
executables:
shop: shopFull lesson: Command-line tools: args, stdin and exit codes →
From Dart to Flutter
What changes in the toolchain
flutter doctor # check the SDK, the toolchains and the devices
flutter create my_app
flutter pub get
flutter run -d chrome
flutter test
flutter analyze
flutter build apk --release
flutter build web --release
flutter pub run build_runner build --delete-conflicting-outputsFull lesson: From Dart to Flutter →
FAQ
Is this Dart cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 5 lessons of the Dart course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Dart course — it carries the worked explanations, the edge cases and the exercises behind every line here.
Related cheat sheets
Last refreshed 2026-09-27.