NAMED CONSTRUCTORS IN DART code example
Example 1: named constructor dart
class Person {
String name;
int age;
Person({this.name = '', this.age = 0});
}
void main() {
Person person1 = Person(name: "Raaj", age: 35);
print(person1.age);
}
Example 2: dart call constructor in constructor
class Chipmunk {
String name;
int fame;
Chipmunk.named(this.name, [this.fame]);
Chipmunk.famous1() : this.named('Chip', 1000);
factory Chipmunk.famous2() {
var result = new Chipmunk.named('Chip');
result.fame = 1000;
return result;
}
}