Why learn Dart?
If you have used a well-made app on an Android phone, an iPhone, a web page and a desktop computer, and it looked and felt the same on all four, there is a fair chance it was built with Flutter, and every Flutter app is written in Dart. Flutter lets one team write one codebase for every platform, and Dart is the language that makes that practical: it compiles to fast native code for phones and desktops, to JavaScript or WebAssembly for browsers, and during development it reloads changed code into a running app in under a second.
Dart is also simply a pleasant, modern language. If you know Java, C#, JavaScript or Kotlin, its syntax will feel familiar within an hour. Underneath the familiar surface it has a sound type system (when the compiler says a variable is a String, it really is, at run time), null safety built into every type, and since Dart 3, records, pattern matching and sealed classes that make modelling data a joy. It runs well outside Flutter too, for command-line tools and servers.
This course teaches the language. Flutter's widget model appears in the last lesson, and once you know Dart well, Flutter's own documentation will make much more sense.
Where Dart came from
Google announced Dart in October 2011 at the GOTO conference in Aarhus, Denmark. Its designers, Lars Bak and Kasper Lund, had previously built V8, the JavaScript engine in Chrome, and the original goal was a better language for large web applications than the JavaScript of the time, with plans for a Dart virtual machine inside Chrome. That plan was dropped in 2015; instead, Dart compiled to JavaScript, and the language found its real home a few years later when Google's Flutter team chose it. Flutter needed a language that could compile ahead of time to fast native code, yet also support instant reloading during development, and Dart's virtual machine could do both.
| Year | Release | What changed |
|---|---|---|
| 2013 | Dart 1.0 | First stable release; types were optional and only checked when asked |
| 2014 | ECMA-408 | Dart standardized by Ecma International |
| 2018 | Dart 2.0 | A sound type system: static types are enforced, with type inference |
| 2018 | Flutter 1.0 | Flutter's first stable release, in December |
| 2021 | Dart 2.12 | Sound null safety, opt-in at first |
| 2023 | Dart 3.0 | Null safety required for all code; records, patterns, class modifiers such as sealed |
| 2024 | Dart 3.3 | Extension types |
| 2024–25 | Dart 3.6 to 3.10 | Digit separators, wildcard variables, null-aware elements, dot shorthands |
| 2026 | Dart 3.12 to 3.14 | Private named parameters, primary constructors, and dart migrate |
Dart now releases a new minor version roughly every three months. The language evolution page lists each one. Every feature is tied to a language version, chosen by the minimum SDK in your project, so an old package keeps compiling the way it always did while new code uses new features. This course was checked with Dart 3.14, and marks features introduced after 3.0 with their version.
One language, several ways to run it
Most languages are either compiled ahead of time (C, Rust, Swift) or run by a virtual machine (Python, JavaScript, Java). Dart does both, deliberately:
- During development,
dart runuses the Dart VM with a JIT (just-in-time) compiler. Programs start quickly, and the VM can replace code in a running program, which is how Flutter's hot reload updates an app without restarting it or losing its state. - For release,
dart compile execompiles AOT (ahead of time) to a self-contained native executable for the current platform. It starts instantly and runs fast, with no VM to install. Flutter apps for phones and desktops ship this way. - For the web,
dart compile jsproduces JavaScript anddart compile wasmproduces WebAssembly (WasmGC), so the same Dart code runs in browsers.
Dart manages memory with a garbage collector tuned for programs, like user interfaces, that create many short-lived objects. You never free memory yourself. One more design choice matters later: Dart runs your code on a single thread per isolate, with an event loop for asynchronous work, and uses separate isolates that share no memory for parallelism. That rules out a whole class of threading bugs, as the lesson on asynchrony will show.
Installing the SDK, or not
The quickest start needs no installation at all: open DartPad, the official online playground, type a program and press Run. DartPad runs real Dart in your browser and can run small Flutter apps too.
For real work, install the Dart SDK by following dart.dev/get-dart, which gives installers and package-manager commands for Windows, macOS and Linux. If you install Flutter, you already have Dart: the Flutter SDK includes it. Then check:
dart --versionOn the machine that checked this course it printed Dart SDK version: 3.14.1 (stable), followed by the build date and platform. For an editor, Visual Studio Code with the official Dart extension, or Android Studio and IntelliJ IDEA with the Dart plugin, all use the analysis server that ships in the SDK, so you get the same errors and fixes as on the command line.
Your first programs
Save this as hello.dart:
void main() {
print('Hello, world!');
}and run it:
dart run hello.dartHello, world!Every Dart program starts at a top-level function called main. void says that it returns nothing. Statements end with semicolons, blocks use braces, and strings may use single or double quotes; Dart's style guide prefers single quotes. print writes a line to the console.
Interpolation and Unicode
void main() {
final greetings = {
'Swahili': 'Habari',
'Japanese': 'こんにちは',
'Hindi': 'नमस्ते',
'Greek': 'Γεια σου',
};
for (final entry in greetings.entries) {
final word = entry.value;
print('${entry.key}: $word has length ${word.length}');
}
const wave = '👋';
print('$wave has length ${wave.length} but ${wave.runes.length} rune');
}Swahili: Habari has length 6
Japanese: こんにちは has length 5
Hindi: नमस्ते has length 6
Greek: Γεια σου has length 8
👋 has length 2 but 1 runefinal declares a variable that is assigned once; the next lesson explains it alongside var and const. The braces { 'Swahili': 'Habari', ... } create a map from keys to values, and greetings.entries walks its key-value pairs in insertion order (Dart's default maps remember the order you added things). Inside a string, $word inserts a variable and ${...} inserts any expression.
Now look at the lengths. Dart's String is a sequence of UTF-16 code units, the same model as Java and JavaScript, and length counts those units. For Japanese, each character happens to be one unit, so you get 5. For Hindi, नमस्ते is six code points and six units, although a reader sees three letters. The waving hand is one Unicode code point (one rune, as Dart calls it) stored as two UTF-16 units, so its length is 2. When you need to count what a reader sees, for example to limit a user's name to 20 letters, use the official characters package from pub.dev, which counts grapheme clusters. Flutter itself depends on it to count what users type.
A function and an arrow
double fahrenheit(double celsius) => celsius * 9 / 5 + 32;
void main() {
const readings = [-10.0, 0.0, 21.5, 37.0, 100.0];
for (final c in readings) {
print('$c °C is ${fahrenheit(c).toStringAsFixed(1)} °F');
}
final hottest = readings.reduce((a, b) => a > b ? a : b);
print('Hottest reading: $hottest °C');
print(
'Average: ${(readings.reduce((a, b) => a + b) / readings.length).toStringAsFixed(2)} °C',
);
}-10.0 °C is 14.0 °F
0.0 °C is 32.0 °F
21.5 °C is 70.7 °F
37.0 °C is 98.6 °F
100.0 °C is 212.0 °F
Hottest reading: 100.0 °C
Average: 29.70 °Cfahrenheit takes a double and returns a double. Its body is a single expression, so it uses arrow syntax: => expression is short for { return expression; }. toStringAsFixed(1) formats a number with one decimal place. reduce combines the list's elements pairwise with the function you pass, here an anonymous function (a, b) => a > b ? a : b that keeps the larger. The const list is a compile-time constant: it can never be changed, and identical constants are shared in memory.
Arguments, libraries and exit codes
main may take the command-line arguments as a parameter, a list of strings. Anything beyond printing, such as files, standard error or the exit status, comes from a library you import. Libraries that ship with the SDK have names starting with dart:; dart:core (numbers, strings, lists, print) is imported automatically.
import 'dart:io';
void main(List<String> arguments) {
if (arguments.isEmpty) {
stderr.writeln('usage: dart run greet.dart <name>');
exitCode = 64;
return;
}
print('Hello, ${arguments.first}!');
}Run as dart run greet.dart Wanjiru, it printed Hello, Wanjiru!. Run with no argument, it printed the usage line to standard error and the process ended with status 64, the conventional code for a usage error. Setting exitCode and returning, rather than calling exit(64), lets the program finish any pending work first. dart:io works on the command line and on servers, but not in browsers, which have package:web instead; code meant to run everywhere sticks to dart:core, dart:async, dart:collection and dart:convert.
Projects and the dart tool
Single files are fine for learning; real programs are packages. Create one:
dart create hello_app
cd hello_app
dart runThe console template creates:
hello_app/
├── pubspec.yaml the package's name, SDK constraint and dependencies
├── analysis_options.yaml lint rules for the analyzer
├── bin/hello_app.dart the program's entry point, with main
├── lib/hello_app.dart library code, importable as package:hello_app/hello_app.dart
└── test/hello_app_test.dartpubspec.yaml says, among other things, sdk: ^3.14.1: the package needs Dart 3.14.1 or a later 3.x, and that minimum also sets the package's language version. dart run finds bin/, compiles and runs it. The everyday commands are all subcommands of dart:
| Command | What it does |
|---|---|
dart run | run a program in the VM (JIT) |
dart compile exe bin/app.dart | build a native executable (AOT) |
dart pub get, dart pub add <name> | fetch dependencies; add one from pub.dev |
dart analyze | report errors, warnings and lint issues |
dart format . | format every file in the official style |
dart test | run the tests in test/ |
dart fix --apply | apply automated fixes suggested by the analyzer |
On this course's machine, dart compile exe turned the hello-world program into an executable of about 6.5 megabytes (most of it the runtime and garbage collector) that printed the same line. It is self-contained: it runs without a Dart installation on any machine with the same operating system and processor architecture.
Common misconceptions
Misconception
"Dart is only for Flutter." Flutter is the main reason people learn Dart, but the SDK alone builds command-line tools and servers, and the language's own tools (the analyzer, the formatter, the package manager) are written in Dart.
Misconception
"Dart is interpreted, so it must be slow." During development the VM compiles code just in time; release builds are compiled ahead of time to native machine code. Flutter apps on phones run AOT-compiled Dart.
Misconception
"length tells me how many letters a string has." It tells you how many UTF-16 code units it has. For English text they coincide; for emoji, many scripts and combined accents they do not. Use runes for code points and the characters package for user-perceived characters.
How professionals work
Dart developers lean heavily on their tools. The analyzer runs continuously in the editor, dart format is applied automatically (formatting is not debated in Dart teams: the formatter decides), and a set of recommended lints, package:lints or the stricter package:flutter_lints for Flutter projects, is enabled from the first day. The official style guide, Effective Dart, covers naming (UpperCamelCase types, lowerCamelCase everything else, lowercase_with_underscores file names), documentation comments with ///, and API design. Read it once now and again after this course; it will make your code look like everyone else's, which is the point.
Exercises
1. Dart and Flutter, first steps
Warm-upComputationalWhat does this program print?
void main() {
final name = 'Ola';
final items = 3;
print('$name has ${items * 2} apples and ${name.length} letters');
}
2. Dart and Flutter, first steps
CoreComputationalThe emoji 👍🏽 (thumbs up with a skin-tone modifier) is two Unicode code points, and each lies outside the Basic Multilingual Plane, so each needs two UTF-16 code units. What does print('👍🏽'.length); print?
3. Dart and Flutter, first steps
CoreComputationalWhat does the second print in this program output?
int square(int x) => x * x;
void main() {
print([1, 2, 3].map(square).toList());
print([1, 2, 3].map(square));
}
4. Dart and Flutter, first steps
CoreHumanA team is developing a Flutter app. Which description of how their Dart code runs is accurate?
5. Dart and Flutter, first steps
Warm-upHumanWhich dart command turns bin/app.dart into a self-contained native executable? Type the command without the file name.
6. Dart and Flutter, first steps
CoreHumanA pubspec.yaml contains sdk: ^3.10.0. Which statement is true?
7. Dart and Flutter, first steps
Warm-upHumanWhich of these can the Dart SDK compile Dart code to? List the letters.
- A. Native machine code
- B. JavaScript
- C. JVM bytecode
- D. WebAssembly
- E. .NET intermediate language
Further reading and resources
- Dart overviewThe official description of the language, its platforms and its compilers.
- Get the Dart SDK
- DartPadThe official playground. Every program in this course can be pasted into it.
- The dart command-line tool
- dart compileNative executables, JavaScript, WebAssembly and snapshots.
- Language evolutionEvery release with its date and what it added to the language.
- Flutter