dart constructor : code example
Example 1: dart this constructor
class MyClass {
int param1;
MyClass(this.param1);
}
final obj = MyClass(100);
class MyClassNamed { // with named parameters
int param1;
MyClassNamed({required this.param1});
}
final objNamedParam = MyClassNamed(param1: 100);
Example 2: 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);
}