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

The `[]` (index) operator in Dart is an overloadable instance method that enables subscript access on objects, allowing them to be queried or mutated using array-like or map-like bracket notation.

In Dart, subscripting is not a built-in language primitive restricted to core collections; rather, it is syntactic sugar for standard method invocations. The operator is divided into two distinct method signatures: one for retrieval (`operator []`) and one for assignment (`operator []=`).

## Syntax and Implementation

To support the index operator, a class must define one or both of the following methods. The following example uses generic type parameters to demonstrate a valid, compilable implementation:

```dart theme={"dark"}
class CustomIndexer<K, V> {
  final Map<K, V> _internalData = {};

  // Handles read access: var x = obj[index];
  V? operator [](K index) {
    return _internalData[index];
  }

  // Handles write access: obj[index] = value;
  void operator []=(K index, V value) {
    _internalData[index] = value;
  }
}
```

## Technical Characteristics

* **Arity Constraints:**
  * `operator []` must accept exactly one parameter (the index).
  * `operator []=` must accept exactly two parameters (the index, followed by the value to assign).
* **Type Flexibility:** The index parameter is not constrained to integers. It can be any valid Dart type, including `String`, `Enum`, or custom objects. This is the underlying mechanism that allows Dart's `Map` to accept arbitrary objects as keys.
* **Return Types:**
  * `operator []` can return any type, including nullable types (`T?`), which is standard practice when an index might be out of bounds or a key might not exist.
  * `operator []=` must have a `void` return type, as the assignment expression evaluates to the assigned value inherently, not via the method's return.
* **Invocation Translation:** The Dart compiler translates bracket notation directly into method calls at compile time. However, unlike standard methods, operator methods cannot be invoked using dot notation with the `operator` keyword (e.g., `instance.operator[](key)` is strictly invalid Dart syntax and will cause a compile-time error). They must be invoked using the bracket syntax:
  * `var x = instance[key];` conceptually invokes the `operator []` method with `key` as the argument.
  * `instance[key] = value;` conceptually invokes the `operator []=` method with `key` and `value` as the arguments.
  * To invoke a superclass implementation, Dart provides the explicit `super[key]` and `super[key] = value` syntax.
* **Null Safety:** If the object being indexed is potentially null, Dart provides the null-aware index operator (`?[]`), which short-circuits the evaluation to `null` without throwing a `NoSuchMethodError` (e.g., `var x = instance?[key];`).

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