पाठ 1 / 25

What Dart Is and Where It Runs

Describe Dart's goals, compilation targets and relationship with Flutter.

A client-optimised language

Dart is an open-source, statically typed, object-oriented language from Google, designed for building fast apps on many platforms. It is best known as the language of Flutter, Google's UI toolkit for Android, iOS, web, Windows, macOS and Linux, but it also runs command-line tools and servers. Dart has a flexible compilation model. During development it runs on the Dart VM with a JIT (just-in-time) compiler, enabling Flutter's hot reload, where code changes appear in a running app in about a second. For release builds it compiles ahead of time (AOT) to native ARM or x64 machine code for fast start-up and predictable performance. For the web it compiles to JavaScript or WebAssembly. Dart 3 (2023) made sound null safety mandatory and added records, patterns and class modifiers, and later releases added features such as extension types. Dart's syntax will feel familiar if you know Java, C#, JavaScript or Kotlin, while its type system and tooling make it pleasant for large codebases.

One language, several targets

Dart runs on the VM with JIT in development and compiles AOT to native code, JavaScript or WebAssembly for release.

A central code icon with arrows to four targets: a gear for the VM, a chip for native code, a browser window and a block representing WebAssembly.
Figure 1.1 — Dart's compilation targets.

A first Dart program

Top-level main, type inference and string interpolation.

void main(List<String> args) {
  final name = args.isNotEmpty ? args.first : 'Asha';   // inferred as String
  var visits = 1;
  visits += 2;

  print('Hello, $name! You have visited $visits times.');
  print('Next year you will be ${age(2000) + 1}.');      // expression in ${}
}

int age(int birthYear) => DateTime.now().year - birthYear;

// terminal:  dart run bin/hello.dart Ravi

Learn Dart before diving deep into Flutter

Flutter code is full of named parameters, const constructors, futures, streams and null-safety operators. A short focus on the language first makes widget code much easier to read.

त्वरित जाँच: Which compilation mode does Flutter use during development to support hot reload?

  • JIT compilation on the Dart VM
  • AOT compilation to native code
  • Compilation to JavaScript only
  • Interpretation without compilation
Answer

JIT compilation on the Dart VM — The JIT on the Dart VM allows code to be updated in a running app.