Optional Arguments in Parameterised Constructor

Note: [ ] for optional argument , { } for named optional argument

void main() {
  
  // Optional argument in Parameterised Constructor
  
  var employee1 = Employee(1, "John", "Doe",position:"CTO", number_of_day_worked:12);

  print(employee1.id);
  print(employee1.firstname);
  print(employee1.lastname);
  print(employee1.position);
  print(employee1.number_of_day_worked);
}

class Employee {
  int id;

  String firstname;

  String lastname;

  String position;

  int number_of_day_worked;

  
  

Employee(this.id,this.firstname,this.lastname,{this. position,this. number_of_day_worked});

}

Last updated