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

A redirecting constructor is a constructor that delegates the instantiation process to another constructor within the same class. Instead of implementing its own initialization logic or body, it forwards its parameters—or computed default values—to a target constructor using the `this` keyword.

## Syntax

A redirecting constructor is defined by appending a colon (`:`) followed by a call to `this(...)` for an unnamed target constructor, or `this.constructorName(...)` for a named target constructor.

```dart theme={"dark"}
class Configuration {
  String environment;
  int timeout;

  // Target unnamed constructor
  Configuration(this.environment, this.timeout);

  // Target named constructor
  Configuration.custom(this.environment, this.timeout);

  // Redirecting to the unnamed constructor
  Configuration.dev(String env) : this(env, 3000);

  // Redirecting to a named constructor
  Configuration.prod(String env) : this.custom(env, 5000);
}
```

## Architectural Rules and Constraints

When defining a redirecting constructor, the Dart compiler enforces strict structural rules:

1. **No Block Body:** A redirecting constructor cannot have a function body. It must terminate immediately with a semicolon after the delegation.
2. **Exclusive Initializer:** The redirection must be the only item in the initialization list. You cannot combine `this(...)` with instance variable initializers, `super(...)` calls, or `assert` statements.
3. **Same-Class Delegation:** The redirection must target a constructor within the exact same class. Delegating to a parent class constructor requires `super`, which is a standard initializer, not a redirecting constructor.
4. **Parameter Evaluation:** The arguments passed to `this(...)` can be parameters received by the redirecting constructor, literal values, or expressions, provided those expressions do not reference `this` (the instance being created).

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

  Point(this.x, this.y);

  // VALID: Terminates with a semicolon and is the exclusive initializer
  Point.xAxis(double x) : this(x, 0.0);

  // INVALID: Cannot have a body
  // Point.yAxis(double y) : this(0.0, y) { print('Created'); } 

  // INVALID: Cannot mix redirection with field initialization
  // Point.diagonal(double val) : x = val, this(val, val); 
}
```

## Constant Redirecting Constructors

If the target constructor is defined as a `const` constructor, the redirecting constructor can also be declared as `const`. The arguments passed in the redirection can be compile-time constants (like literals) or the parameters passed directly into the redirecting constructor itself.

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

  // Constant target constructor
  const ImmutablePoint(this.x, this.y);

  // Constant redirecting constructor passing its own parameter
  const ImmutablePoint.xAxis(double x) : this(x, 0.0);

  // Constant redirecting constructor passing literal constants
  const ImmutablePoint.origin() : this(0.0, 0.0);
}
```

## Factory Redirecting Constructors

Dart also supports redirecting *factory* constructors. While standard redirecting constructors delegate to another constructor in the *same* class, a redirecting factory constructor delegates the creation of the object to a constructor of a *different* class (typically a concrete subclass). This is denoted using the `=` operator rather than a colon.

```dart theme={"dark"}
abstract class Logger {
  // Redirecting factory constructor
  factory Logger(String name) = ConsoleLogger;
}

class ConsoleLogger implements Logger {
  final String name;

  // Target constructor for the factory redirection
  ConsoleLogger(this.name);
}
```

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