Skip to main content
An initializer list is a comma-separated sequence of expressions placed between a constructor’s parameter list and its body, prefixed by a colon (:). It executes before the constructor body runs and before the superclass constructor is invoked, allowing for the assignment of instance variables before the object is fully instantiated.

Execution Order

When a constructor is invoked, Dart processes the initialization phase in a strict sequence:
  1. Initializer list expressions (evaluated from left to right).
  2. Superclass constructor.
  3. Main class’s constructor body.

Scope and Restrictions

  • No this Access: The right-hand side of an initializer expression does not have access to the this keyword. You cannot invoke instance methods or read instance variables within the initializer list because the object is in an uninitialized state.
  • Final Variables: It is the primary mechanism for initializing final instance variables that require computation or parameter mapping before the constructor body executes.
  • Redirection Isolation: If an initializer list contains a redirecting constructor call (this(...)), it cannot contain any other initializers.

Syntax Mechanics

Variable Assignment and Assertions The list can contain direct assignments to instance variables and assert statements for parameter validation.
Superclass Delegation The initializer list is used to explicitly invoke a superclass constructor using super(...). If omitted, Dart implicitly calls the superclass’s unnamed, no-argument constructor.
Constructor Redirection When delegating to another constructor within the same class, the initializer list consists solely of the this(...) call.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More