Initial Setup
This guide walks you through installing the Dart SDK and setting up your development environment for Dart programming.
Installing Dart SDK
The Dart SDK includes the Dart VM, core libraries, and command-line tools needed for Dart development.
Windows Installation
Using Chocolatey (Recommended):
Open PowerShell as Administrator and run:
choco install dart-sdkUsing Direct Download:
- Visit dart.dev/get-dart
- Download the Windows installer
- Run the installer and follow the prompts
- Add Dart to your system PATH (installer does this automatically)
Verify installation:
dart --version
# => Output: Dart SDK version: 3.x.x (stable)macOS Installation
Using Homebrew (Recommended):
brew tap dart-lang/dart
brew install dartVerify installation:
dart --version
# => Output: Dart SDK version: 3.x.x (stable)Linux Installation
Using apt (Debian/Ubuntu):
sudo apt update
sudo apt install apt-transport-https
wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
sudo apt update
sudo apt install dartVerify installation:
dart --version
# => Output: Dart SDK version: 3.x.x (stable)Optional: Installing Flutter SDK
If you plan to build mobile, web, or desktop applications with Flutter, install the Flutter SDK (which includes Dart).
Why Install Flutter?
- Hot reload - Instant code updates during development
- Rich UI framework - Build beautiful cross-platform interfaces
- Includes Dart - Flutter SDK includes Dart SDK automatically
- Unified tooling - Single tool for mobile, web, and desktop
Flutter Installation Steps
Windows:
- Download Flutter SDK from flutter.dev
- Extract the zip file to desired location (e.g.,
C:\src\flutter) - Add
C:\src\flutter\binto system PATH - Run
flutter doctorto check dependencies
macOS:
cd ~/development
unzip ~/Downloads/flutter_macos_*.zip
export PATH="$PATH:`pwd`/flutter/bin"
flutter doctorAdd to .zshrc or .bash_profile:
export PATH="$PATH:$HOME/development/flutter/bin"Linux:
cd ~/development
tar xf ~/Downloads/flutter_linux_*.tar.xz
export PATH="$PATH:`pwd`/flutter/bin"
flutter doctorAdd to .bashrc:
export PATH="$PATH:$HOME/development/flutter/bin"Verify Flutter installation:
flutter doctor
# => Checks all Flutter dependencies
# => Reports any missing requirements
flutter --version
# => Output: Flutter 3.x.x • Dart 3.x.xIDE Setup
Choose your preferred IDE and install Dart/Flutter plugins.
Visual Studio Code (Recommended)
Why VS Code?:
- Lightweight and fast
- Excellent Dart/Flutter extensions
- Integrated terminal
- Free and open-source
Installation steps:
- Install Visual Studio Code
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search and install “Dart”
- (Optional) Search and install “Flutter” if using Flutter
Verify setup:
Create a test file test.dart:
void main() {
print('Hello from VS Code!'); // => Output: Hello from VS Code!
}Run with F5 or right-click → “Run Without Debugging”
Android Studio / IntelliJ IDEA
Why Android Studio/IntelliJ?:
- Powerful refactoring tools
- Advanced debugging
- Built-in Flutter tools
- Professional IDE features
Installation steps:
- Install Android Studio or IntelliJ IDEA
- Open Settings/Preferences
- Go to Plugins
- Search and install “Dart”
- (Optional) Search and install “Flutter” if using Flutter
- Restart IDE
Verify setup:
- Create new Dart project: File → New → Project → Dart
- Select Dart SDK location
- Create a simple application
- Run with Shift+F10
Command-Line Only
You can use any text editor and run Dart from the command line:
Popular editors:
- Vim with dart-vim-plugin
- Emacs with dart-mode
- Sublime Text with Dart plugin
- Notepad++ with Dart syntax highlighting
Running Dart files:
dart run filename.dart
# => Executes Dart fileYour First Dart Project
Create your first Dart project to verify everything works.
Using Command Line
# Create project directory
mkdir zakat_calculator
cd zakat_calculator
# Initialize Dart project
dart create . --template console
# => Creates project structure:
# => - bin/ (executable scripts)
# => - lib/ (library code)
# => - test/ (test files)
# => - pubspec.yaml (project configuration)Project structure created:
zakat_calculator/
├── bin/
│ └── zakat_calculator.dart # Main entry point
├── lib/
│ └── zakat_calculator.dart # Library code
├── test/
│ └── zakat_calculator_test.dart # Unit tests
├── pubspec.yaml # Dependencies
├── analysis_options.yaml # Linting rules
└── README.md # Project documentationHello World Program
Edit bin/zakat_calculator.dart:
void main() {
// => Entry point of the program
print('As-salamu alaykum! Welcome to Dart!'); // => Output greeting
// => Prints to console
}Run the program:
dart run bin/zakat_calculator.dart
# => Output: As-salamu alaykum! Welcome to Dart!Package Management with pubspec.yaml
Dart uses pubspec.yaml for dependency management, similar to package.json in Node.js or requirements.txt in Python.
Understanding pubspec.yaml
name: zakat_calculator # => Project name (lowercase with underscores)
description: A Zakat calculator application. # => Brief description
version: 1.0.0 # => Semantic versioning
environment:
sdk:
">=3.0.0 <4.0.0" # => Dart SDK version constraints
# => Requires Dart 3.x
dependencies: # => Runtime dependencies
intl:
^0.18.0 # => Internationalization package
# => Caret (^) allows compatible updates
dev_dependencies: # => Development-only dependencies
lints: ^3.0.0 # => Dart linting rules
test: ^1.24.0 # => Testing frameworkInstalling Packages
Add a package:
Edit pubspec.yaml to add dependencies, then run:
dart pub get
# => Downloads dependencies
# => Creates pubspec.lock (lockfile)
# => Updates .dart_tool/ directoryCommon packages:
- intl - Internationalization and formatting
- http - HTTP client for REST APIs
- path - File path manipulation
- test - Unit testing framework
Using Packages in Code
import 'package:intl/intl.dart'; // => Import intl package
void main() {
var formatter = NumberFormat.currency(
// => Create currency formatter
locale: 'id_ID', // => Indonesian locale
symbol: 'Rp', // => Currency symbol: Rupiah
decimalDigits: 0, // => No decimal places
);
double zakat = 1250000; // => Zakat amount: 1,250,000 IDR
print('Zakat: ${formatter.format(zakat)}'); // => Output: Zakat: Rp1.250.000
// => Formatted with locale
}Running Dart Programs
Direct Execution
Run a Dart file directly:
dart run bin/program.dart
# => Executes program
# => Uses JIT compilation (fast startup for development)Compiled Executable
Compile to native executable for production:
dart compile exe bin/program.dart -o zakat_calculator
# => Compiles to native machine code
# => Output: zakat_calculator executable
# => Uses AOT compilation (fast execution)
./zakat_calculator
# => Run compiled executable
# => No Dart VM requiredBenefits of compilation:
- Faster startup time
- No Dart SDK required on target machine
- Smaller memory footprint
- Production-ready deployment
Running Tests
dart test
# => Runs all tests in test/ directory
# => Reports pass/fail statusVerifying Your Installation
Run this checklist to ensure everything is properly installed:
Dart SDK Check
dart --version
# => Should output: Dart SDK version: 3.x.xPackage Manager Check
dart pub --version
# => Should output: Dart SDK version: 3.x.xCreate and Run Test Project
mkdir test_project
cd test_project
dart create . --template console
dart run
# => Should output: Hello world: 42!IDE Plugin Check
Open your IDE and verify:
- Dart syntax highlighting works
- Code completion suggests Dart keywords
- Can run Dart files from IDE
- Error highlighting shows syntax errors
Flutter Check (If Installed)
flutter doctor
# => Checks Flutter installation
# => Reports any issues
flutter --version
# => Shows Flutter and Dart versionsTroubleshooting Common Issues
Dart Command Not Found
Problem: dart: command not found
Solution:
- Windows: Ensure Dart is added to system PATH
- macOS/Linux: Add Dart to PATH in
.bashrc,.zshrc, or.bash_profile:
export PATH="$PATH:/usr/lib/dart/bin"Reload shell configuration:
source ~/.bashrc # or ~/.zshrcPermission Denied on Linux/macOS
Problem: Permission denied when running dart pub get
Solution: Fix ownership of Dart cache:
sudo chown -R $USER ~/.pub-cacheIDE Not Recognizing Dart
Problem: IDE doesn’t recognize Dart syntax or SDK
Solution:
- Verify Dart plugin is installed and enabled
- Configure Dart SDK path in IDE settings
- Restart IDE after installing plugins
- Ensure project has
pubspec.yamlfile
Flutter Doctor Reports Issues
Problem: flutter doctor shows X marks
Solution: Follow the specific recommendations from flutter doctor output. Common fixes:
- Install missing Android SDK components
- Accept Android licenses:
flutter doctor --android-licenses - Install Xcode command-line tools (macOS):
xcode-select --install
Next Steps
Now that you have Dart installed and configured, proceed to:
- Quick Start - Build a complete Zakat Calculator application
- By Example - Learn through annotated code examples
- By Concept - Deep dive into Dart concepts
Continue to Quick Start to build your first real Dart application.