ZetCode

Introduction to Dart

last modified May 30, 2026

This is an introduction to the Dart programming language. Dart first appeared in 2011 and is developed by Google. The website of the language is https://dart.dev/.

An online development environment is available at https://dartpad.dev/.

Dart Programming Language

Dart is a modern, client-optimized language designed for fast development of high-performance applications across multiple platforms, including mobile, desktop, server, and web. Dart offers clean and approachable syntax that is easy to learn for developers familiar with languages like JavaScript, Java, or C#.

Dart is particularly well-suited for building user interfaces, especially with Flutter. It supports productive workflows such as hot reload, allowing developers to see changes quickly without restarting the app.

Key features of Dart include:

Dart powers Flutter, Google's UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.

Dart continues to evolve, offering developers an efficient way to create modern cross-platform applications.

Dart installation

Dart is easy to install on Linux, macOS, and Windows. For current instructions, see the official installation page:

https://dart.dev/get-dart

On Debian-based Linux distributions (after adding the Dart APT repository), we can install Dart with:

$ sudo apt-get update
$ sudo apt-get install dart
$ dart --version
Dart SDK version: 3.12.0 (stable) (Fri May 8 01:51:14 2026 -0700) ...

After a successful installation, we can verify the installed SDK with the --version command.

For VS Code, install the Dart extension, which provides language support, code completion, and debugging.

Dart simple example

The following is a simple example in Dart.

main.dart
void main() {
  print('First program in Dart');
}

The program prints a message to the console. Dart source files use the .dart extension. The main function is the entry point of the program. The function is preceded by the void keyword, which indicates that it does not return a value.

The body of the function is enclosed in a pair of curly brackets. The print function displays a message in the console. Statements are terminated with a semicolon.

$ dart main.dart
First program in Dart

Dart variables

Variables store references to values.

main.dart
void main() {
  final String name = 'John Doe';
  final int age = 34;

  print('$name is $age years old');
}

In the example, we have a string and an integer variable. The variable names are preceded by String and int data types.

final String name = 'John Doe';

We can create string literals both with single and double quotes. The final keyword indicates that the variable is immutable.

print('$name is $age years old');

Dart supports string interpolation. Variables prefixed with the $ character are evaluated to their values inside strings.

$ dart main.dart
John Doe is 34 years old

Dart user input

The dart:io library provides file, socket, HTTP, and other I/O support for non-web applications.

main.dart
import 'dart:io';

void main() {
  stdout.write('Enter your name: ');
  final name = stdin.readLineSync() ?? 'Guest';
  print('Hello $name\n');
}

The example prompts the user for a name and prints a greeting.

stdout.write('Enter your name: ');

We can use the stdout.write function to write to the console without a newline character.

final name = stdin.readLineSync() ?? 'Guest';

We read the user input with stdin.readLineSync. Since this function can return null, we provide a default value with the null-coalescing operator (??).

$ dart main.dart
Enter your name: Peter
Hello Peter

Source

Dart Guides
Dart Language Tour

This was an introduction to the Dart programming language.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Dart tutorials.