Skip to content

Language guide

Learn Dart

The language behind Flutter, for building mobile, desktop and web apps from one codebase.

Dart on SkillAIVibe

Written guide

SkillAIVibe does not run Dart in the browser yet, so this page is a written guide: what the language is, a complete first program, how to run it on your own computer, and a learning order. Languages that do run here are listed on the Learn to Code hub.

What Dart is

Dart is a statically typed, object-oriented language from Google, written with the braces, semicolons and classes familiar from Java, C# and JavaScript. Its type system is null-safe: the compiler tracks which variables are allowed to be empty and will not build code that ignores that case. Most people learn Dart because it is the language of Flutter, where a change to the code can be pushed into an app while the app is still running.

Where Dart is used

Cross-platform apps with Flutter
Flutter apps, and Flutter's widget framework itself, are written in Dart; one codebase can be built for Android, iOS, the web, Windows, macOS and Linux.
Web front-ends
Dart compiles to JavaScript and to WebAssembly, which is how Flutter apps run in a browser.
Command-line tools
dart compile exe produces a self-contained native executable. Dart Sass, the main implementation of the Sass stylesheet language, is written in Dart.
Server-side code
The Dart team's shelf package provides the pieces of an HTTP server, which lets a backend share its data classes with a Flutter app.
Code generation
Tools such as build_runner, themselves Dart programs, generate repetitive code like JSON serialisation inside Flutter and Dart projects.

Your first Dart program

Saved as hello.dart. Run it with the steps in the next section.

dart
void main() {
  String name = 'Asha';
  var steps = 4;
  final languages = ['Dart', 'Python', 'Go'];

  print('Hello, $name.');
  print('Twice $steps is ${steps * 2}.');
  print('$name has tried ${languages.length} languages.');
}

What it prints

Output
Hello, Asha.
Twice 4 is 8.
Asha has tried 3 languages.
  1. Line 1 declares main, the function every Dart program starts in. void means it hands nothing back, and the braces hold its body.
  2. Line 2 writes the type out, String, and ends with a semicolon, as every statement must. Dart style prefers single quotes for text, though double quotes behave the same.
  3. Line 3 uses var, so Dart infers that steps is an int and will refuse text in it later. Line 4 uses final, meaning the variable cannot be reassigned; the square brackets make a List.
  4. Line 6 prints a line, and print adds the newline. Inside the quotes, $name is replaced by the variable's value; the full stop after it cannot be part of a name, so Dart knows where the name ends.
  5. Lines 7 and 8 insert more than a bare name, an expression and a property, so they need braces: ${steps * 2} and ${languages.length}. Written as $steps * 2, line 7 would print 4 * 2 as literal text.

Run Dart on your own computer

Dart is one SDK with the compiler, runtime, formatter, analyzer and pub package manager behind a single dart command. If Flutter is your goal, install Flutter instead; it includes a matching copy of Dart.

  1. Install the Dart SDK, or Flutter

    The Get Dart page on dart.dev lists the route for each system: Homebrew on macOS, an apt repository or zip archive on Linux, and Chocolatey or a zip archive on Windows. The Flutter SDK's bin folder also contains the dart command.

  2. Check it works

    Open a new terminal so it picks up the updated PATH. Any Dart 3 release is fine; some tutorials written for Dart 2 show code that no longer compiles.

    Shell
    dart --version
  3. Save the file and run it

    Save the first program as hello.dart and run it from the folder it is in. The file is compiled and run in one step.

    Shell
    dart run hello.dart
  4. Create a project when one file is not enough

    dart create sets up a pubspec.yaml for the project's packages, plus bin, lib and test folders. Inside it, dart format applies the official style and dart analyze reports errors without running anything; the Dart extensions for VS Code and IntelliJ-based editors do the same as you type.

    Shell
    dart create my_app

A learning order for Dart

Stages, not a timetable. Each one exists because the next would not make sense without it, and how long each takes depends on how much you write.

  1. Stage 1. Syntax, variables and types

    • main() and print()
    • var, final and const
    • int, double, String and bool
    • string interpolation
    • ~/ for whole-number division

    Dart checks types before the program runs, so from the first line you are learning how the compiler reasons. The var, final and const distinction appears in every Flutter file.

  2. Stage 2. Control flow and functions

    • if, for and while
    • switch expressions
    • functions and return types
    • named and optional parameters
    • arrow syntax with =>

    Flutter widget constructors lean heavily on named parameters, and short arrow functions appear wherever a callback is passed, so both are worth practising before any app code.

  3. Stage 3. Collections and null safety

    • List, Map and Set
    • collection if and collection for
    • nullable types with ?
    • the ?., ?? and ! operators
    • late variables

    Null safety is the idea newest to most learners, and it touches every line that handles data which might be missing. It is easier to grasp with plain lists and maps than inside a screen layout.

  4. Stage 4. Classes and objects

    • fields, methods and constructors
    • named constructors and this.field shorthand
    • inheritance and implicit interfaces
    • mixins
    • records and patterns

    Every value in Dart is an object, and a Flutter app is a tree of objects. Records and patterns, added in Dart 3, give lighter ways to return several values and unpack them.

  5. Stage 5. Asynchronous code

    • Future, async and await
    • try and catch
    • Stream and await for
    • isolates for heavy work

    Apps spend much of their time waiting on the network, files or the user. A missing await is easy to write and hard to spot, so this deserves care before you build apps.

  6. Stage 6. Packages, tests and Flutter

    • pubspec.yaml and dart pub add
    • packages from pub.dev
    • tests with package:test
    • a first Flutter app with hot reload

    With the language settled, Flutter becomes one new thing to learn instead of two. If Flutter is not your goal, a command-line tool or small HTTP server makes a good first project.

Mistakes beginners make in Dart

Silencing null-safety errors with !
Adding ! tells the compiler a nullable value is definitely not null, which makes the error go away. If that turns out to be wrong, the program crashes at run time with 'Null check operator used on a null value'. Check with an if or give a fallback with ??, and keep ! for cases you can prove.
Forgetting await
An async function called without await hands back a Future, a placeholder for a result that has not arrived yet. Printing it shows something like Instance of 'Future<String>', and the next line runs before the work has finished. Mark the calling function async and await the call.
Leaving the braces off an interpolated property
'$user.name' inserts the whole user object as text, followed by the literal word .name, so the output is Instance of 'User'.name. Anything beyond a bare variable name, whether a property, a method call or arithmetic, needs braces: '${user.name}'.
Expecting / to give a whole number
In Dart, / always returns a double: 7 / 2 is 3.5, and even 6 / 2 is 3.0. So int half = 7 / 2; does not compile. Use ~/ for whole-number division; 7 ~/ 2 is 3.
Mixing up final and const
Both prevent reassignment, but const also needs a value known at compile time, so const now = DateTime.now(); is rejected. final fixes only the variable, not the object: a final List can still have items added. In Flutter, a const widget can be created once and reused, which is why const appears so often.

Strengths and trade-offs

Where it is strong

  • Sound null safety, which rules out a whole family of crashes before the program runs.
  • A just-in-time compiler during development, which is what makes Flutter's hot reload possible, and ahead-of-time compilation to native code for the finished app.
  • Conventional syntax, so anyone who knows Java, C#, Kotlin or JavaScript can spend their effort on the new ideas rather than the punctuation.
  • The formatter, analyzer, compilers and package manager all come in the one SDK download.

Where it is not

  • Outside Flutter the ecosystem is small: server and command-line Dart work, but with far fewer libraries, guides and answered questions than Node.js, Python or Go have for the same jobs.
  • In practice, learning Dart means learning Flutter. Without that goal, a more widely used language covers the same ground.
  • Dart on the web cannot use npm packages directly, and a Flutter web app has a larger initial download than a typical hand-built JavaScript page.
  • The language has changed a lot between versions. Dart 3 made null safety compulsory, so many older tutorials and forum answers show code that no longer compiles.

Who Dart is for

Dart is the right language for anyone who wants to build apps with Flutter, from a first phone app to a product that has to run on mobile, desktop and the web. As a first language it is workable: the syntax is conventional and the analyzer explains problems clearly, although mobile development also means installing Android Studio or, on a Mac, Xcode. If you want a broad foundation for data work, scripting or backend services, Python, JavaScript or Go will take you further. If you already know Java, Kotlin, C# or TypeScript, Dart will be the easy part of learning Flutter.

Questions about learning Dart

Do I need to learn Dart before Flutter?
You need the core of it: types, functions with named parameters, classes, null safety, and async with await. Learning those at the same time as widgets and layout makes both harder, and small plain Dart programs teach them without an emulator. Isolates, advanced mixins and writing your own packages can wait until a project needs them.
Is Dart only used for Flutter?
No, but Flutter is the main reason it is used. Dart also runs command-line programs, HTTP servers and code compiled for the web. Those uses are real, but the libraries and community help around them are much thinner than for Python, JavaScript or Go, so Dart outside Flutter makes most sense when it shares code with a Flutter app.
Is Dart like JavaScript or Java?
It looks like both, with braces, semicolons and classes. Unlike JavaScript, it is statically typed and null-safe, so many mistakes are caught before the code runs, and there is no undefined, only null. Unlike Java, it has type inference with var, functions that live outside classes, and named parameters.
Do I need a Mac to build Flutter apps?
Only for iPhone and iPad apps, because building them requires Xcode, which runs only on macOS. On Windows or Linux you can build Flutter apps for Android, the web and the desktop system you are using, and plain Dart programs run on all three.

The primary source

When this guide and the official documentation disagree, the documentation is right and we would like to hear about it.

Other languages

All languages and paths · Programming glossary · Your progress