> ## 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 Late Final Field

A `late final` field in Dart is a class-level variable that combines deferred initialization (`late`) with strict runtime immutability (`final`). It allows a non-nullable field to bypass compile-time definite assignment checks, deferring its initialization until runtime, while guaranteeing that the field's reference can only be assigned exactly once.

## Syntax

```dart theme={"dark"}
// 1. Lazy Initialization (Assigned at declaration)
late final Type fieldName = expression;

// 2. Deferred Assignment (Unassigned at declaration)
late final Type fieldName;
```

## Core Mechanics

The behavior of a `late final` field depends on whether it is declared with an initializer.

### 1. With an Initializer (Lazy Evaluation)

When a `late final` field is declared with an assignment, the evaluation of the right-hand expression is deferred.

* The expression is executed **only upon the first read access** of the field.
* Once evaluated, the result is permanently bound to the field.
* Because it is `final`, the field cannot be reassigned after this initial lazy evaluation.

```dart theme={"dark"}
class EvaluationExample {
  // _expensiveComputation() is not called during instantiation.
  // It is called exactly once, the first time `value` is read.
  late final int value = _expensiveComputation();

  int _expensiveComputation() {
    return 42;
  }
}
```

### 2. Without an Initializer (Deferred Assignment)

When declared without an assignment, the field acts as a write-once variable whose initialization is detached from the class constructor.

* **Write-Once:** The field can be assigned a value at any point during runtime, but strictly only once.
* **Runtime Enforcement:** Any attempt to reassign the field after its initial assignment will throw a `LateInitializationError`.
* **Read Before Write:** Attempting to read the field before it has been assigned will also throw a `LateInitializationError`.

```dart theme={"dark"}
class AssignmentExample {
  late final String token;

  void initializeToken(String value) {
    token = value; // Valid: First assignment
  }

  void reassignToken() {
    token = "new_token"; // Throws LateInitializationError: Field 'token' has already been initialized.
  }

  void readToken() {
    print(token); // Throws LateInitializationError if called before initializeToken()
  }
}
```

## Memory and State Implications

By using `late final`, the Dart analyzer shifts the safety guarantees of non-nullable types from compile-time to runtime. Standard `final` fields require memory allocation and assignment before the constructor body executes (via declaration or initializer lists). A `late final` field allocates the memory for the reference, but leaves the memory uninitialized (or points it to a hidden sentinel value) until the runtime assignment occurs, at which point the memory address is locked.

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