Dart Introduction

Dart is a modern programming language developed by Google, designed for building high-performance, cross-platform applications.

This chapter introduces you to Dart's origins, design philosophy, and its broad application scenarios in frontend, mobile, and backend development.


The History and Design Goals of Dart

Dart was born in 2011, with the initial goal of replacing JavaScript as the browser's native scripting language.

Although this goal was not achieved, Dart hit a critical turning point in 2017—the release of the Flutter framework brought Dart back into developers' view.

Dart's design goals are very clear:

Design goalsDescription
High PerformanceSupports AOT (Ahead-of-Time) and JIT (Just-in-Time) compilation, enabling rapid development while generating native code.
Strong typingSupports type inference, balancing type safety with development efficiency.
Cross-platformA single codebase can be compiled to ARM, x64 machine code, or JavaScript.
Easy to learnSyntax borrowed from mainstream languages such as Java, JavaScript, and C#, reducing the learning cost.
Null safetyBuilt-in Null Safety mechanism, avoiding null pointer exceptions at the language level.

Dart 2.0 was released in 2018, marking the language's maturity. Dart 3.0 was released in 2023, further strengthening features such as the type system and pattern matching.


Application Scenarios of Dart

Dart's application scenarios are very broad, covering full-stack development needs from mobile to backend.

Mobile Development (Flutter)

This is Dart's most core application scenario at present.

Through the Flutter framework, Dart can build native applications for both iOS and Android platforms, with a single codebase running on both.

Web Development

Dart can be compiled to JavaScript for building web frontend applications.

AngularDart is Google's maintained Dart version of the Angular framework, suitable for large-scale web projects.

Server-side development

With the dart:io library and frameworks such as Shelf, Dart can also be used to write high-performance server-side applications.

Multiple server-side projects inside Google are written in Dart.

Command-line tools

Dart can be compiled into standalone executable files, making it well-suited for writing cross-platform CLI tools.

application scenariosCompilation targetsTypical frameworks/tools
MobileARM machine codeFlutter
Web front-endJavaScriptAngularDart
Server-sideMachine code / JITShelf、Dart Frog
Command lineMachine codedart compile exe

Dart vs JavaScript

Both Dart and JavaScript are object-oriented languages, but Dart is more rigorous in language design.

Below is a comparison of their differences across several dimensions:

Comparison DimensionDartJavaScript
Type systemStrong typing, supports type inferenceWeak typing, dynamic typing
Null safetyBuilt-in Null SafetyNone (requires TypeScript or manual checking)
Entry functionMust have a main() functionDirect script execution
Classes and inheritanceClass-based OOP, single inheritancePrototype chain-based
Compilation methodAOT + JIT dual modeJIT-based
Concurrency modelIsolate (message passing)Worker threads / event loop
Package managementpub.dev (unified official repository)npm (community repository)

If you have a JavaScript background, learning Dart will be very easy—their async syntax (async/await) is almost identical.

However, Dart's type system and null safety mechanism will give you a greater sense of security in large projects.

Example

A comparison of how the same functionality is written in the two languages:

// JavaScript version
function greet(name) {
  if (name === null || name === undefined) {
    return 'Hello, stranger!';
  }
  return `Hello, ${name}!`;
}

console.log(greet('example'));
console.log(greet(null));
// Dart version — null safety makes types clearer
String greet(String? name) {
  // name may be null, needs explicit handling
  if (name == null) {
    return 'Hello, stranger!';
  }
  return 'Hello, $name!';
}

void main() {
  print(greet('example'));
  print(greet(null));
}
Hello, example!
Hello, stranger!

The relationship between Dart and Flutter

Many people first encounter Dart because of Flutter.

In fact, Flutter is Dart's "killer app," but Dart itself is an independent general-purpose programming language.

The reasons Flutter chose Dart are as follows:

  • JIT compilationSupports Hot Reload—seeing results in sub-seconds after modifying code, greatly improving development efficiency.
  • AOT compilationGenerates native machine code, apps start fast and run smoothly, without the performance overhead of a JavaScript Bridge
  • Dart's declarative UINaturally fits with Flutter's Widget tree structure
  • Unified technology stackGoogle maintains both the language and the framework simultaneously, ensuring good version compatibility.

Before learning Flutter, it is recommended to first master the basics of Dart. After understanding the language features, the learning curve for Flutter will be much smoother. This tutorial is prepared for this purpose.


A brief history of Dart version development

VersionRelease dateImportant Features
Dart 1.02013First stable version, basic language features
Dart 2.02018Strong type system, with new/const being optional.
Dart 2.122021Introduced Null Safety
Dart 3.02023Pattern matching, Records, class modifiers.

This tutorial is written based on Dart 3.x versions, and all code examples have been verified on Dart 3.0 and above.

other extensions