Dart Introduction
Every Flutter app is written in Dart, a modern, object-oriented language created by Google. Before you build screens with widgets, it pays to get comfortable with Dart itself — and the good news is that Dart is easy to read if you have seen JavaScript, Java, C# or Kotlin before.
In this first part of the course every example is plain Dart. Press ▶ Run and the code is compiled and executed for real, so you can experiment freely.
Why Dart?
Dart was designed for building user interfaces. A few properties make it a great fit for Flutter:
| Feature | Why it matters |
|---|---|
| Ahead-of-time (AOT) compilation | Release apps compile to fast native ARM/x64 code |
| Just-in-time (JIT) compilation | During development Flutter can hot reload your changes in under a second |
| Sound null safety | The compiler proves a variable can't be null unless you allow it |
| Familiar C-style syntax | Curly braces, semicolons, if, for, classes — nothing exotic |
| Rich standard library | Collections, async Future/Stream, JSON and more are built in |
| Single-threaded event loop | No data races in UI code; async/await keeps the UI responsive |
Dart also compiles to JavaScript and WebAssembly, which is how Flutter apps run in the browser.
Your first Dart program
Every Dart program starts in a top-level function called main. The print function writes a line of text to the console.
void main() {
print('Hello, Dart!');
}Hello, Dart!
Some things to notice:
voidmeansmaindoes not return a value.- Strings can use single quotes
'…'or double quotes"…". The Dart style guide prefers single quotes. - Every statement ends with a semicolon
;.
Tip: In every playground you can edit the code and press Ctrl+Enter to run it again.
Several statements
Statements run from top to bottom. Here we also use a comment — anything after // is ignored by the compiler.
void main() {
// Each print call writes one line.
print('Dart is productive.');
print('Dart is fast.');
print('Dart powers Flutter!');
}Dart is productive.
Dart is fast.
Dart powers Flutter!
Dart supports three kinds of comments:
// A single-line comment
/* A multi-line
comment */
/// A documentation comment — tools like `dart doc`
/// and your IDE show this text as API documentation.Values inside text
You can embed a value in a string with $name, or a whole expression with ${...}. This is called string interpolation and you will use it constantly.
void main() {
var language = 'Dart';
var year = 2011;
print('$language was announced in $year.');
print('That is ${2025 - year} years before 2025.');
}Dart was announced in 2011.
That is 14 years before 2025.
How Dart code runs
When you work on a Flutter app, the dart and flutter tools do the compiling for you:
| Command | What it does |
|---|---|
dart run |
Runs a Dart console program |
dart compile exe |
Produces a native executable |
dart format |
Formats your code in the official style |
dart analyze |
Finds errors and style problems without running the code |
flutter run |
Builds and launches a Flutter app on a device or emulator |
You don't need any of these for this course — the playgrounds run on a remote compiler — but you will meet them again in the Flutter Get Started lesson.
Dart and Flutter: how they fit together
Flutter is a UI framework; Dart is the language it is written in. Your app's code, the Flutter framework itself and most packages you install are all Dart. That means:
- Everything you learn in this section — variables, functions, classes, async code — is used directly in Flutter.
- Widgets are just Dart classes. A screen is an object that builds other objects.
- Flutter's famous hot reload is possible because Dart can inject updated code into a running app.
Note: Dart examples in this course import only
dart:core(automatic),dart:async,dart:convertanddart:collection, which run anywhere. Flutter widget examples later use a simulated preview.
Test yourself
Which function is the entry point of every Dart program?
- start()
- run()
- main()
- init()
What does print('Total: ${2 + 3}') output?
- Total: ${2 + 3}
- Total: 5
- Total: 2 + 3
- Total: 23
Which Dart feature lets Flutter apply code changes to a running app in about a second?
- AOT compilation
- Hot reload via JIT compilation
- Null safety
- Garbage collection