Cascade notation

void main() {
  var employee1 = Employee();

//   employee1.id = 1;

//   employee1.firstname = "John";

//   employee1.lastname = "Doe";

//   employee1.position = "CTO";

  employee1
    ..id = 1
    ..firstname = "John"
    ..lastname = "Doe"
    ..position = "CTO";

  print(employee1.toString());
}

class Employee {
  int id;

  String firstname;

  String lastname;

  String position;

  @override
  String toString() {
    return "id : $id , firstname : $firstname , lastname : $lastname, position : $position";
  }
}

Using the cascade notation with methods is also known as method chaining . You are consecutively calling methods i.e. chaining methods

Last updated