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.
Architectural Rules and Constraints
When defining a redirecting constructor, the Dart compiler enforces strict structural rules:- No Block Body: A redirecting constructor cannot have a function body. It must terminate immediately with a semicolon after the delegation.
- Exclusive Initializer: The redirection must be the only item in the initialization list. You cannot combine
this(...)with instance variable initializers,super(...)calls, orassertstatements. - 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. - Parameter Evaluation: The arguments passed to
this(...)can be parameters received by the redirecting constructor, literal values, or expressions, provided those expressions do not referencethis(the instance being created).
Constant Redirecting Constructors
If the target constructor is defined as aconst 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.
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.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





