Skip to main content
A List in Dart is an ordered, zero-indexed collection of objects. It serves as the Dart implementation of an array and utilizes generics (List<E>) to enforce compile-time type safety. A List implements the Iterable<E> interface, inheriting a wide array of functional collection methods.

Memory and Mutability Types

Dart lists operate in three primary mutability states regarding their length and element assignment:
  1. Growable (Default): Backed by a dynamic array. The internal buffer resizes automatically when the capacity is exhausted.
  2. Fixed-length: Memory is pre-allocated. Elements can be modified via index, but operations that alter the length (e.g., add, remove) throw an UnsupportedError.
  3. Unmodifiable: Neither the length nor the individual elements can be mutated.

Instantiation Syntax

Lists are typically instantiated using collection literals or factory constructors.

Collection Operators

Dart provides specialized syntactic sugar for declarative list composition directly within literals.
  • Spread Operator (...): Unpacks an Iterable into the current list.
  • Null-aware Spread (...?): Unpacks an Iterable only if it is not null.
  • Collection if: Conditionally includes an element.
  • Collection for: Iterates and inserts elements inline.

Core API Surface

Because List<E> implements Iterable<E>, it shares many traversal methods but adds index-based access and mutation capabilities.

Inspection Properties

Mutation Methods (Growable Lists Only)

Functional Transformations

Methods like map and where return a lazy Iterable<E>. To evaluate the iterable and allocate the result into a new concrete array in memory, .toList() must be invoked.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More