Dart basics

Install the SDK and learn values, collections, functions, objects and null safety.

How to use this path

Install the SDK and learn values, collections, functions, objects and null safety. Follow the chapter order on your first pass; use the topic directory when reviewing a specific question. Predict an example, run it, then change one input and explain the result.

Complete server, file and test examples belong in a local Dart project. Browser-supported language examples load the compiler only when requested.

What this section covers

Build a typed program, validate input and explain the data used by an everyday app.

Dart setup and fundamentals

Install Dart, run a program and learn values, operators, strings and control flow.

  1. Install and verify Dart SDKChoose the Dart SDK included with Flutter or install standalone Dart, then verify which executable your tools use.
  2. Your first Dart projectCreate a package, find its entry point and verify formatting, analysis and execution.
  3. Variables and typesUse var, final and const deliberately, and let Dart types help you express what a value means.
  4. Operators and numbersUse integer minor units, arithmetic, comparisons and boolean rules for a small order.
  5. Strings, parsing and interpolationNormalize text, parse optional numbers and avoid treating malformed input as valid data.
  6. Conditions and loopsChoose branches, iterate with for and while, and use break and continue intentionally.
  7. Types, casts and exceptionsUse static types, safe checks and explicit exceptions instead of relying on dynamic access.
  8. Collections and control flowChoose lists, sets and maps, then use conditions and loops to express a small learning-plan example.

Lists, sets, maps and iterables

Manage real collections, construct data conditionally and transform values deliberately.

  1. Lists and sortingAdd, filter, sort and copy a list without accidentally changing the original order.
  2. Sets, maps and lookupUse set membership and typed map updates for a practical stock summary.
  3. Collection buildersBuild request fields and menu items with conditional, spread and null-aware elements.
  4. Iterable and aggregationTransform, filter and aggregate typed data while understanding lazy evaluation.

Functions and reusable behavior

Name operations, choose parameter contracts and use closures and callbacks.

  1. Functions and named parametersUse explicit inputs, return values and named parameters to make a small Dart function understandable at the call site.
  2. Transforming collectionsUse where, map and fold to filter data, create labels and calculate a result without mutating the original list.
  3. Closures and scopeCapture configuration deliberately and keep independent function instances from sharing accidental state.
  4. Callbacks and function typesPass behavior through a typed callback instead of coupling a workflow to one output channel.
  5. Exceptions and result contractsChoose an explicit boundary for parsing errors and preserve actionable failure information.
  6. Callable objects and tear-offsPass behavior without calling it early and give configured operations a clear owner.

Objects and null safety

Build domain models with constructors, explicit nullability and controlled mutation.

  1. Classes and modelsCreate an immutable Dart model with a constructor, getter and behavior that belongs with the data.
  2. Null safetyUse nullable types, checks and defaults to handle missing data without treating the non-null assertion as a shortcut.
  3. Constructors and factoriesUse named constructors, initializer lists, factories and const objects for deliberate model creation.
  4. Getters, setters and privacyExpose readable state while keeping mutation rules inside the owning object.
  5. Enums and domain statesRepresent a finite set of states with meaningful data and behavior.
  6. Immutable models and copyWithCreate a changed model without mutating a shared object and distinguish shallow from deep immutability.

Find your next idea

Search lessons, code examples and projects.

Type a few words to start exploring.