Initializer list

Initializer list

// Initializer list sets instance variables before the constructor body runs. 
Point.fromJson(Map<String, num> json) 
   : x = json['x'], 
   y = json['y'] { 
      print('In Point.fromJson(): ($x, $y)'); 
}

Besides invoking a superclass constructor, you can also initialize instance variables before the constructor body runs.

During development, you can validate inputs by using assert in the initializer list.

Note:

The right-hand side of an initializer does not have access to this.

Order of execution

  1. Initializer list.
  2. Superclass’s no-arg constructor.
  3. Main class’s no-arg constructor.

Initializer list — Structure map

Clickable & Draggable!

Initializer list — Related pages: