> ## 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 Final Class

A `final` class in Dart is a class modifier that completely restricts subtyping outside of its declaring library. It guarantees that the class hierarchy is closed to external modification, preventing external code from either extending or implementing the class, while still permitting unrestricted instantiation.

## Core Mechanics

* **Instantiation:** A `final` class can be instantiated from any library.
* **Extension (`extends`):** Prohibited outside the declaring library. Allowed within the declaring library.
* **Implementation (`implements`):** Prohibited outside the declaring library. Allowed within the declaring library.
* **Mixin Application (`with`):** Prohibited outside the declaring library.

## Syntax and Library Boundaries

The behavior of a `final` class strictly depends on the library boundary (typically the file boundary, unless `part` directives are used).

**File 1: `core_library.dart` (Declaring Library)**

```dart theme={"dark"}
// Declaration of a final class
final class NetworkRequest {
  void send() => print('Sending request...');
}

// VALID: Subtyping is allowed within the same library.
// Note: Subclasses must propagate the restriction (see rules below).
final class GetRequest extends NetworkRequest {}
base class PostRequest implements NetworkRequest {
  @override
  void send() => print('Sending POST...');
}
```

**File 2: `external_module.dart` (External Library)**

```dart theme={"dark"}
import 'core_library.dart';

void main() {
  // VALID: Instantiation is allowed anywhere.
  NetworkRequest req = NetworkRequest();
  req.send();
}

// ERROR: Cannot extend a final class outside its library.
class PutRequest extends NetworkRequest {} 

// ERROR: Cannot implement a final class outside its library.
class MockRequest implements NetworkRequest {
  @override
  void send() {}
}
```

## Modifier Propagation Rules

Dart enforces strict modifier propagation to prevent external code from bypassing the `final` restriction via a subclass. If a class extends or implements a `final` class within the same library, that subclass must be explicitly marked with one of the following modifiers:

1. `final`: Completely closes the subclass to external subtyping.
2. `base`: Allows external extension, but prohibits external implementation.
3. `sealed`: Creates an abstract, exhaustively switchable subclass that also restricts external subtyping.

```dart theme={"dark"}
final class Parent {}

// VALID
final class ChildA extends Parent {}
base class ChildB extends Parent {}
sealed class ChildC extends Parent {}

// ERROR: The subclass must be marked base, final, or sealed.
class ChildD extends Parent {} 
```

## Interaction with Other Modifiers

* **`abstract final class`:** The class cannot be instantiated anywhere, and cannot be subtyped outside its own library. It acts purely as an internal base class or interface.
* **`interface` vs `base` vs `final`:**
  * `interface` blocks external `extends`.
  * `base` blocks external `implements`.
  * `final` blocks **both** external `extends` and `implements`.

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