> ## 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 Null-Aware Index

The `?[]` (null-aware index) operator conditionally evaluates access to a collection's elements. It returns the value at the specified index or key if the collection evaluates to a non-null object, and short-circuits to return `null` if the collection reference evaluates to `null`.

```dart theme={"dark"}
expression?[index]
```

## Evaluation Mechanics

When the Dart compiler encounters `expression?[index]`, it executes the following logic:

1. It evaluates the base `expression` exactly once.
2. If the result is `null`, the operation immediately yields `null`. It does not attempt to evaluate the `index` expression or invoke the underlying `[]` method.
3. If the result is a non-null object, it evaluates the `index` expression and invokes the standard `[]` (index) operator on that object.

Because the `?[]` operator evaluates the base expression exactly once, it is semantically distinct from a naive ternary operation (`expression != null ? expression[index] : null`), which evaluates the base expression twice. The single-evaluation guarantee of `?[]` prevents redundant computations or unintended side effects when the base expression is a method call. Its behavior is accurately represented by binding the evaluated base expression to a temporary variable:

```dart theme={"dark"}
// Semantic equivalent of expression?[index]
final temp = expression;
temp == null ? null : temp[index];
```

## Type Resolution

The return type of a `?[]` operation is inherently forced to be nullable, regardless of the collection's generic type arguments.

* If a collection is typed as `List<T>?`, the expression `collection?[index]` resolves to type `T?`.
* Even if the collection contains non-nullable elements (e.g., `List<int>?`), the result of the null-aware index operation must be assigned to a nullable variable (e.g., `int?`).

## Syntax Examples

**List Indexing:**

```dart theme={"dark"}
List<int>? nullableList = null;
int? result1 = nullableList?[0]; // Evaluates to null

nullableList = [10, 20, 30];
int? result2 = nullableList?[0]; // Evaluates to 10
```

**Map Key Access:**

```dart theme={"dark"}
Map<String, double>? nullableMap = null;
double? value1 = nullableMap?['pi']; // Evaluates to null

nullableMap = {'pi': 3.14159};
double? value2 = nullableMap?['pi']; // Evaluates to 3.14159
```

## Null-Aware Index Assignment

Dart allows a null-aware index expression (`?[]`) to be used as an assignable target (l-value) in conjunction with the standard assignment operator (`=`). There is no distinct `?[]=` operator token; rather, the language permits the null-aware index syntax on the left side of an assignment.

This allows mutation of a collection at a specific index only if the collection is not null. If the base collection evaluates to `null`, the entire assignment operation short-circuits—the assignment is silently ignored, and the right-hand side expression is never evaluated.

```dart theme={"dark"}
List<int>? numbers = null;
numbers?[0] = 42; // Operation short-circuits; numbers remains null

numbers = [1, 2, 3];
numbers?[0] = 42; // numbers is now [42, 2, 3]
```

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