> ## 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 Named Constructor

A named constructor is an explicitly identified constructor that allows a class to define multiple instantiation paths. Because Dart does not support constructor overloading by parameter signature, named constructors provide the mechanism to declare multiple constructors within a single class while explicitly defining the initialization behavior.

## Syntax

A named constructor is defined by appending a dot (`.`) and an identifier to the class name.

```dart theme={"dark"}
class ClassName {
  // Unnamed constructor
  ClassName() { 
    // ... 
  }

  // Named constructor
  ClassName.identifier(parameters) {
    // Initialization logic
  }

  // Private named constructor
  ClassName._privateIdentifier(parameters) {
    // Initialization logic
  }
}
```

## Technical Characteristics

**1. No Inheritance**
Named constructors are not inherited by subclasses. If a subclass needs to be instantiated using a named constructor defined in its superclass, the subclass must explicitly declare its own constructor (named or unnamed) and invoke the superclass's named constructor via the initializer list.

**2. Constructor Redirection**
A named constructor can delegate initialization to another constructor within the same class using the `this` keyword in the initializer list. When redirecting, the constructor body must remain empty.

**3. Superclass Invocation**
A named constructor can invoke a specific named constructor of its superclass using the `super.identifier()` syntax within the initializer list. This invocation must occur before any local constructor body executes.

**4. Factory Modifiers**
Named constructors can be declared with the `factory` keyword. A factory named constructor does not strictly allocate a new instance; it can return an existing instance from a cache or return an instance of a subtype.

**5. Private Named Constructors**
By prefixing the named constructor's identifier with an underscore (`_`), the constructor becomes private to its declaring library. This is a structural pattern used to restrict external instantiation, force the use of factory constructors, or implement singletons.

## Implementation Mechanics

The following code demonstrates the structural mechanics of named constructors, including standard initialization, redirection, superclass delegation, and private access control.

```dart theme={"dark"}
class Point {
  double x;
  double y;

  // Standard generative unnamed constructor
  Point(this.x, this.y);

  // Named constructor using an initializer list
  Point.origin() 
      : x = 0.0, 
        y = 0.0;

  // Named constructor redirecting to the standard constructor
  Point.alongXAxis(double x) : this(x, 0.0);

  // Private named constructor restricting external access
  Point._internal(this.x, this.y);
}

class Point3D extends Point {
  double z;

  // Subclass named constructor delegating to a superclass named constructor
  Point3D.origin() 
      : z = 0.0, 
        super.origin();
}

void main() {
  // Instantiation via named constructors
  final p1 = Point.origin();
  final p2 = Point.alongXAxis(5.0);
  final p3 = Point3D.origin();
  
  // Point._internal(1.0, 1.0); // Compilation error if called outside the library
}
```

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