Python Constructors: Initializing Formals & Initializer Lists
Dart eliminates constructor boilerplate using **Initializing Formals** (`Point(this.x, this.y);`), which directly assigns arguments to fields before the constructor body runs. When complex validation or superclass setup is required, **Initializer Lists** (`: assert(x > 0), this.y = compute(x)`) execute before the constructor body.
"Initializing formals are like a direct vacuum tube delivery: packages sent into the tube land directly in their assigned storage bins without requiring manual unpacking."
Deep Dive: How It Works
Initializing Formals (`this.fieldName`): Directly assigns constructor parameters to instance fields without manual `this.x = x` assignments.
Initializer List (`:`): A comma-separated list of expressions that execute *before* the constructor body and before `super()`.
Null Safety Invariant: Non-nullable final fields MUST be initialized either at declaration, via initializing formals, or in the initializer list.
Syntax Blueprint
class Point {
final double x;
final double y;
// Initializing formals + Initializer list
Point(this.x, this.y) : assert(x >= 0, "x cannot be negative");
}Initializing formals binding fields directly with initializer list assertion.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Trying to assign a non-nullable `final` field inside the `{ ... }` constructor body.Why it happens: By the time the constructor body runs, all final fields must already be initialized.
How to fix: Use initializing formals (`this.field`) or initializer lists (`: field = expr`).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Build Circle with Initializer List
Create class `Circle` with `final double radius; final double area;`.
Use constructor `Circle(this.radius) : area = 3.14159 * radius * radius;`.
In `main()`, instantiate `Circle(10.0)` and print `Area: ${circle.area}`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.