> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart List

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.

```dart theme={"dark"}
// 1. Growable List Literal (Type inferred as List<int>)
var growableList = [1, 2, 3];

// 2. Fixed-length List Constructor
// Creates a list of length 3, initialized with 'A'.
List<String> fixedList = List.filled(3, 'A', growable: false);

// 3. Generated List Constructor
// Creates a list by invoking a callback for each index.
List<int> generatedList = List.generate(5, (index) => index * 2);

// 4. Unmodifiable List Constructor
List<double> lockedList = List.unmodifiable([1.1, 2.2, 3.3]);
```

## 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.

```dart theme={"dark"}
List<int> baseList = [2, 3];
List<int>? nullList;
bool includeFour = true;

List<int> composedList = [
  1,
  ...baseList,          // Unpacks: 2, 3
  ...?nullList,         // Ignored because it is null
  if (includeFour) 4,   // Evaluates to: 4
  for (var i in baseList) i * 10 // Evaluates to: 20, 30
];
// Result: [1, 2, 3, 4, 20, 30]
```

## Core API Surface

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

### Inspection Properties

```dart theme={"dark"}
List<String> items = ['a', 'b', 'c'];

int len = items.length;       // 3
bool empty = items.isEmpty;   // false
String first = items.first;   // 'a' (Throws StateError if empty)
String last = items.last;     // 'c' (Throws StateError if empty)
```

### Mutation Methods (Growable Lists Only)

```dart theme={"dark"}
List<int> nums = [1];

nums.add(2);                  // Appends single element: [1, 2]
nums.addAll([3, 4]);          // Appends iterable: [1, 2, 3, 4]
nums.insert(0, 0);            // Shifts elements right: [0, 1, 2, 3, 4]
nums.removeAt(2);             // Removes element at index 2: [0, 1, 3, 4]
nums.removeWhere((e) => e>3); // Removes based on predicate: [0, 1, 3]
```

### 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.

```dart theme={"dark"}
List<int> values = [1, 2, 3, 4];

// Filtering (Returns lazy Iterable, evaluated into a new List)
List<int> evens = values.where((e) => e.isEven).toList();

// Transformation (Returns lazy Iterable, evaluated into a new List)
List<String> strings = values.map((e) => e.toString()).toList();

// Accumulation (Returns a single value of type E)
int sum = values.reduce((value, element) => value + element);
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
