dart-sdk
Dart is a client-optimized language for developing fast apps on any platform. Install via x-cmd for instant access and enhanced productivity.
| Language | dart |
| Homepage | https://dart.dev/ |
x install dart-sdk
| darwin/brew | sh
|
| (win|wsl2)/choco | sh
|
| (win|wsl2)/scoop | sh
|
Dart SDK: The Cross-Platform Language Behind Flutter
Tired of juggling different frameworks for cross-platform development? Want one codebase running on mobile, web, and desktop without drowning in JavaScript ecosystem complexity? Dart is Google's client-optimized language that evolved from Flutter's foundation into a standalone full-stack solution—type-safe, fast to compile, and efficient to run, handling everything from CLI tools to graphical applications.
Dart's core philosophy is the balance between developer productivity and runtime performance. It offers modern language features (null safety, pattern matching, asynchronous streams) while covering all major platforms through flexible compilation strategies: JIT compilation enables hot reload for rapid iteration, while AOT compilation generates native machine code for production performance.
Why Choose Dart
Full Platform Coverage, One Codebase
Dart's real competitive advantage lies in its diverse compilation targets:
| Compilation Target | Technical Approach | Use Case |
|---|---|---|
| Native Mobile | AOT compilation to ARM/x64 machine code | iOS/Android apps |
| Desktop | AOT compilation to Windows/macOS/Linux executables | Cross-platform desktop software |
| Web | Compilation to JavaScript or WebAssembly | Browser applications |
| Server | JIT/AOT running on Dart VM or native binary | CLI tools, backend services |
This flexibility means you can write command-line tools, web backends, mobile apps, and even browser frontends in Dart—consistent language features and standard library across all targets.
Modern Type System, Null Safety Built-In
Dart 3 introduced sound null safety that eliminates null pointer exceptions at the language level. The type system supports generics, function types, record types, and pattern matching commonly used in Flutter development:
// Record type destructuring
var (name, age) = getUserInfo();
// Pattern matching
switch (response) {
case (status: 200, body: var data) => processData(data);
case (status: var code, _) => handleError(code);
}Hot Reload Accelerates Development Cycle
The JIT-based development mode supports hot reload, showing code changes within milliseconds. This is a massive productivity boost for UI development and prototyping—no waiting for recompilation and app restarts.
SDK Core Components
Installing Dart SDK gives you a complete development toolchain:
| Command | Purpose | Typical Usage |
|---|---|---|
dart | Run Dart programs or REPL | dart run bin/main.dart |
dart analyze | Static code analysis | Check type errors and code style |
dart compile | Compile to executables | Support exe, aot-snapshot, js formats |
dart create | Project scaffolding | dart create my_cli |
dart pub | Package management | pub get, pub upgrade |
dart test | Run tests | Execute unit tests in project |
dart fix | Auto-fix issues | Apply code migration suggestions |
dart format | Code formatting | Unify code style |
dart doc | Generate documentation | Generate API docs from doc comments |
dart compile supports multiple output formats:
- exe: Self-contained executable (includes runtime)
- aot-snapshot: AOT-compiled standalone snapshot, requires
dartaotruntime - jit-snapshot: JIT-compiled dependency snapshot
- js: Compile to JavaScript
- wasm: Compile to WebAssembly
Installing Dart SDK
Dart SDK supports Windows, macOS, and Linux. Quick installation via x-cmd is recommended, with system package managers also supported.
Option 1: Install via x-cmd (Recommended)
x env use dartAfter installation, Dart commands are immediately available without manual PATH configuration.
Option 2: Install via Homebrew (macOS/Linux)
brew tap dart-lang/dart
brew install dartOption 3: Install via Chocolatey (Windows)
choco install dart-sdkOption 4: Install via Scoop (Windows)
scoop install dartVerify Installation
dart --versionExample output:
Dart SDK version: 3.6.0 (stable) (Tue Dec 10 23:15:34 2024 +0000) on "macos_arm64"Check SDK installation path and tools:
dart infoYour First Dart Program
Create a file hello.dart:
void main() {
print('Hello, Dart!');
// Null safety example
String? nullable;
String nonNullable = 'required';
// Pattern matching
var numbers = [1, 2, 3];
var [first, ...rest] = numbers;
print('First: $first, Rest: $rest');
}Run the program:
# Run directly (JIT mode)
dart hello.dart
# Compile to native executable
dart compile exe hello.dart -o hello
./hello
# Compile to JavaScript
dart compile js hello.dart -o hello.jsPackage Management and Ecosystem
Dart uses the pub tool for dependency management, with the package repository at pub.dev.
Initialize a project:
dart create my_project
cd my_projectExample pubspec.yaml:
name: my_project
version: 1.0.0
dependencies:
http: ^1.1.0
path: ^1.8.0
dev_dependencies:
test: ^1.24.0Common commands:
# Install dependencies
dart pub get
# Upgrade dependencies
dart pub upgrade
# Add dependency
dart pub add http
# Run tests
dart testCommand-Line Application Development
Dart excels at building cross-platform CLI tools. When compiled to native executables, they can be distributed as single files:
import 'dart:io';
void main(List<String> arguments) {
if (arguments.isEmpty) {
print('Usage: mycli <command>');
exit(1);
}
switch (arguments[0]) {
case 'hello':
print('Hello from Dart CLI!');
case 'version':
print('v1.0.0');
default:
print('Unknown command: ${arguments[0]}');
}
}Compile and distribute:
dart compile exe bin/mycli.dart -o mycli
# The generated mycli runs directly on the target platformAsynchronous Programming Model
Dart's single-threaded event loop with async/await makes asynchronous code as clear as synchronous:
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> fetchData() async {
try {
final response = await http.get(Uri.parse('https://api.example.com/data'));
if (response.statusCode == 200) {
print('Data: ${response.body}');
}
} catch (e) {
stderr.writeln('Error: $e');
}
}
void main() async {
await fetchData();
}For CPU-intensive tasks, Dart provides Isolate for true parallel computation without blocking the main thread.
Relationship with Flutter
Dart is the programming language of the Flutter framework, but the Dart SDK itself is standalone. Even without mobile development, Dart has value as a general-purpose programming language:
- Server-side development: Build web backends with frameworks like
shelf,dart_frog - CLI tool development: Compile to native binaries, fast startup, minimal dependencies
- Script automation: Type-safe, more maintainable than shell scripts
- Web applications: Compile directly to JavaScript or WebAssembly
Comparison with Other Languages
| Dimension | Dart | TypeScript | Go | Swift |
|---|---|---|---|---|
| Type System | Null safety, generics, pattern matching | Gradual types, complex type gymnastics | Clean static types | Safe static types |
| Compilation Targets | Native, JS, WASM | JS | Native | Native |
| Concurrency Model | Isolate + async/await | Event loop (runtime dependent) | Goroutine | Actor + async/await |
| Hot Reload | Supported | Requires additional tools | Not supported | Partial support (Playground) |
| Package Management | pub | npm/yarn/pnpm | go mod | Swift Package Manager |
| Primary Use Cases | Cross-platform UI, full-stack | Web frontend/Node | Backend, cloud-native, CLI | Apple ecosystem |
Dart's advantage lies in cross-platform consistency—learn one language, build various applications. Flutter's popularity has driven Dart's ecosystem, but even outside Flutter, Dart's design as a modern programming language is solid.
Development Tool Support
Dart has comprehensive toolchain support:
- VS Code: Official Dart/Flutter plugin with IntelliSense, debugging, refactoring
- Android Studio / IntelliJ IDEA: Deep integration, suitable for large projects
- Dart DevTools: Performance profiling, memory inspection, widget inspection (Flutter)
- DartPad: Browser-based online Dart editor for quick experiments
Learning Resources
- Official Docs: dart.dev
- Language Guide: dart.dev/language
- API Reference: api.dart.dev
- Package Repository: pub.dev
- GitHub: github.com/dart-lang/sdk
Summary
Dart is a pragmatic modern programming language. It doesn't chase syntax novelty but finds practical balance between developer productivity, runtime performance, and platform coverage. If you're already using Flutter, understanding Dart helps write more elegant code. If you need a toolchain covering CLI, web backend, and desktop apps, Dart is worth evaluating.
Installing Dart SDK through x-cmd takes just one command, and you can start writing and running Dart programs within minutes. Whether it's rapid iteration with hot reload or high-performance deployment with AOT compilation, Dart's toolchain delivers.
Reference: Dart Official Website | Dart SDK GitHub | pub.dev Package Repository | Homebrew Formulae
Help us make these docs great!
All X-CMD docs are generated from command help and multiple data sources. See something that's wrong or unclear? Feel free to let us know through any of these ways~