Every programming environment has a toolchain — the set of programs you use every day to build, run, test, and debug. Dart's tools are clean, fast, and composable. Learning them thoroughly is as important as learning the language itself.
Overview of the Dart Toolchain
Dart Developer Toolchain
-------------------------
+-------------------+
| Dart SDK | Core: VM, libraries, compilers
+-------------------+
|
+----+----+
| |
dart pub
(CLI) (packages)
|
+--+--+
| dev |
tools (browser-based profiling/debugging)
The four main tool categories:
- Dart SDK — the complete development and production toolchain
dartCLI — the primary command for running and managing Dart code- Pub tool — Dart's package manager
- Dart DevTools — performance and debugging suite
The Dart SDK
The Dart SDK is the complete package you download from dart.dev. It contains everything needed for both development and production.
Development Toolchain
| Feature | Description |
|---|---|
| Fast incremental compilation | Only recompiles changed files |
| Stateful hot reload | Update running code without losing app state |
| JIT compilation | Compile and run code immediately |
| Dart Analyzer | Static analysis and linting |
Production Toolchain
| Feature | Description |
|---|---|
| AOT compilation | Compile to fast native machine code |
| Smallest runtime | Minimal overhead in production |
| Tree shaking | Remove unused code from the final binary |
SDK Contents
Dart SDK/
├── bin/
│ ├── dart <-- Main CLI tool
│ └── dartaotruntime <-- AOT runtime
├── lib/
│ ├── core/ <-- dart:core
│ ├── async/ <-- dart:async
│ ├── convert/ <-- dart:convert
│ └── ... <-- Other standard libraries
└── include/ <-- C headers for embedding
The `dart` Command
The dart command is your primary interface to the Dart toolchain. It is a single entry point for all development tasks.
Running Programs
# Run a Dart script directly (JIT)
dart run lib/main.dart
# Run a named script defined in pubspec.yaml
dart run my_script
# Run tests
dart test
Managing Packages
# Install all dependencies listed in pubspec.yaml
dart pub get
# Add a new package
dart pub add http
# Add a dev-only package
dart pub add --dev test
# Remove a package
dart pub remove http
# Upgrade all packages to latest compatible versions
dart pub upgrade
# Show dependency tree
dart pub deps
Code Analysis
# Run the static analyzer
dart analyze
# Verbose analysis output
dart analyze -v
# Analyze a specific file
dart analyze lib/main.dart
The analyzer catches:
- Type errors
- Null safety violations
- Unused variables and imports
- Style violations (based on the configured linting rules)
- Deprecated API usage
Code Formatting
# Format all Dart files in the project
dart format .
# Format a specific file
dart format lib/main.dart
# Check formatting without modifying files (useful in CI)
dart format --output=none --set-exit-if-changed .
Creating Projects
# Create a new Dart console project
dart create my_project
# Create a specific project type
dart create --template=console my_cli_app
dart create --template=package my_library
dart create --template=server-shelf my_server
The Pub Tool
Pub is Dart's package manager. It manages the pubspec.yaml file, resolves dependency versions, and connects to pub.dev, the official Dart package repository.
pubspec.yaml
Every Dart project has a pubspec.yaml that declares dependencies, metadata, and configuration.
name: my_app
description: A sample Dart application
version: 1.0.0
environment:
sdk: '>=3.0.0 <4.0.0'
dependencies:
http: ^1.1.0
intl: ^0.18.0
dev_dependencies:
test: ^1.24.0
lints: ^2.0.0
Common pub Commands
# Install all dependencies
dart pub get
# Add a package (updates pubspec.yaml automatically)
dart pub add http
# Upgrade packages
dart pub upgrade
# Downgrade packages to the minimum allowed versions
dart pub downgrade
# Check for outdated packages
dart pub outdated
# Publish your own package to pub.dev
dart pub publish
# Verify the package before publishing
dart pub publish --dry-run
Version Constraints
dependencies:
# Exact version
some_package: 1.2.3
# Compatible with 1.x (caret range)
http: ^1.1.0 # >=1.1.0 <2.0.0
# Greater than or equal to
intl: ">=0.18.0"
# Range
logger: ">=1.0.0 <2.0.0"
# Any version
some_dev_tool: any
Dart DevTools
Dart DevTools is a browser-based suite of performance and debugging tools for Dart and Flutter applications. It connects to a running app and provides deep visibility into its execution.
# Launch DevTools for a running Flutter app
flutter pub global activate devtools
flutter pub global run devtools
# Or from the flutter CLI
flutter run --verbose
# Then open the DevTools URL printed in the console
Performance Profiling
The Performance view monitors your application in real time.
Performance Profiler
---------------------
Timeline events
--> UI thread frame times
--> Raster thread frame times
--> Dart isolate events
CPU profiler
--> Call stacks sampled over time
--> Identify hot functions consuming most CPU time
--> Flame chart visualization
Features:
- Identify which functions consume the most CPU time
- Spot jank (frames exceeding 16ms that cause visible stuttering)
- Track garbage collection activity
- Monitor isolate behavior
Memory Analysis
The Memory view helps identify memory leaks and optimize allocation patterns.
Memory Analysis
---------------
Heap snapshot at point in time
--> Object type histogram
--> Allocation call stacks
--> Reference paths (what's keeping an object alive)
Memory timeline
--> Heap size over time
--> GC events
--> Allocation rate
Features:
- Take heap snapshots and compare them to find leaks
- Track which lines of code allocate the most memory
- Identify objects that should have been garbage collected but were not
Widget Inspector (Flutter)
The Widget Inspector provides a live, interactive view of the Flutter widget tree.
Widget Inspector
-----------------
Widget tree visualization
--> Expand / collapse widget subtrees
--> Select any widget to inspect its properties
Property panel
--> Widget type and constructor parameters
--> Size, position, and layout constraints
--> Enabled state and theme data
Features:
- Click any widget in the inspector to highlight it on the device screen
- View layout constraints and sizing
- Diagnose layout overflow and rendering issues
Third-Party Tools
Shell Scripting
Dart can be used as a scripting language for automation tasks:
// script.dart
import 'dart:io';
void main() async {
final result = await Process.run('flutter', ['build', 'apk', '--release']);
print(result.stdout);
if (result.exitCode != 0) {
stderr.write(result.stderr);
exit(result.exitCode);
}
}
Makefile
A Makefile can orchestrate common development tasks:
.PHONY: analyze format test build
analyze:
dart analyze
format:
dart format .
test:
dart test
build:
flutter build apk --release
Continuous Integration (CI)
Integrate Dart tools into your CI pipeline:
# .github/workflows/dart.yml
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart pub get
- name: Analyze
run: dart analyze
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
- name: Run tests
run: dart test
Tool Reference
Common Commands Quick Reference
---------------------------------
dart run <file> Run a Dart program
dart test Run all tests
dart analyze Static analysis
dart format . Format all files
dart pub get Install dependencies
dart pub add <pkg> Add a package
dart pub upgrade Upgrade packages
dart pub publish Publish to pub.dev
dart create <name> Create a new project
These tools, used together, form a complete and professional development workflow. The faster you internalize them, the more time you spend writing code and the less time you spend fighting your tools.