> ## 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 Base Mixin Class

A `base mixin class` in Dart is a compound class modifier that defines a construct capable of being instantiated, extended, or mixed in, while strictly prohibiting external implementation. By applying the `base` modifier, it guarantees that all subtypes inherit the actual implementation of the class rather than just its interface, enforcing a closed implementation hierarchy outside its defining library.

## Syntax

```dart theme={"dark"}
base mixin class Name {
  // State and behavior
}
```

## Core Mechanics and Restrictions

The behavior of a `base mixin class` is the intersection of the rules governing `base`, `mixin`, and `class` modifiers:

1. **Inheritance Restrictions (`mixin class`)**: A `mixin class` **cannot have an `extends` clause** or a **`with` clause**. It must directly extend `Object`. It is structurally forbidden from inheriting from other classes or mixing in other mixins.
2. **Instantiation and Constructors (`class` / `mixin class`)**: It can be instantiated directly, provided it is not marked `abstract`. However, because it acts as a `mixin class`, it **cannot declare any constructors whatsoever**. This prohibition applies to both generative constructors (including an explicit empty default constructor like `Name();`) and `factory` constructors. It must rely entirely on the implicit default constructor.
3. **Extension (`base` / `class`)**: It can be extended using the `extends` keyword from any library.
4. **Mixing (`mixin`)**: It can be mixed into other classes using the `with` keyword from any library. It cannot declare an `on` clause because it is declared as a `class`.
5. **Implementation Restriction (`base`)**: It **cannot** be implemented using the `implements` keyword outside of the library in which it is defined.
6. **Subtype Enforcement (`base`)**: The **modifier propagation** (or subtype restriction) rule applies to all subtypes. Any declaration that becomes a subtype—whether by extending (`extends`), mixing in (`with`), implementing (`implements`, which is only allowed in the defining library), or using it as a mixin constraint (`on`)—must explicitly declare a modifier that preserves the base restriction. Subtype classes must be marked `base`, `final`, or `sealed`, and subtype mixins must be marked `base`.

## Structural Rules Visualization

To understand the enforcement boundaries and structural limitations, consider the following cross-library interaction.

**`library_a.dart` (Defining Library)**

```dart theme={"dark"}
class SuperClass {}
mixin SomeMixin {}

// ERROR: A mixin class cannot have an `extends` clause.
// base mixin class InvalidExtendedSystem extends SuperClass {}

// ERROR: A mixin class cannot have a `with` clause.
// base mixin class InvalidMixedSystem with SomeMixin {}

// VALID: Directly extends Object (implicitly) and has no constructors.
base mixin class CoreSystem {
  String version = '1.0.0';
  
  // ERROR: Cannot declare ANY constructors (generative or factory) in a mixin class.
  // CoreSystem();
  // factory CoreSystem.create() => CoreSystem();

  void initialize() => print('System initialized');
}

// ALLOWED: Implementing within the same library is permitted.
// MUST be marked base, final, or sealed to satisfy modifier propagation.
base class LocalMock implements CoreSystem {
  @override
  String version = 'Mock-1.0.0';
  @override
  void initialize() => print('Mock initialized');
}

// ALLOWED: Using as an `on` constraint within the same library.
// MUST be marked base to satisfy modifier propagation.
base mixin SystemExtension on CoreSystem {
  void extendedAction() => print('Action on $version');
}
```

**`library_b.dart` (Consuming Library)**

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

// ALLOWED: Instantiation (relies entirely on the implicit default constructor)
final system = CoreSystem();

// ALLOWED: Extending (Must be marked base, final, or sealed)
final class ExtendedSystem extends CoreSystem {
  void customMethod() {}
}

// ALLOWED: Mixing in (Must be marked base, final, or sealed)
base class MixedSystem with CoreSystem {
  void customMethod() {}
}

// ERROR: Cannot implement a base class outside its defining library.
// class IllegalSystem implements CoreSystem { ... }

// ERROR: All subtypes must be base, final, or sealed.
// class InvalidExtendedSystem extends CoreSystem { ... }
```

## Modifier Compatibility

* **`abstract`**: A `base mixin class` can be prefixed with `abstract` (`abstract base mixin class`). This removes the ability to instantiate it directly while retaining the extension, mixing, and base implementation rules.
* **Mutually Exclusive Modifiers**: It cannot be combined with `interface`, `final`, or `sealed`, as Dart enforces a single access-control modifier per class declaration.

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