I encountered a problem when writing the constructor in dart. I have a class with two final variables, initialize them in the constructor, the following is wrong, because the final variable has no setter method:
class Person{
final String name;
final int age;
// Error
Person(String name, int age) {
this.name = name;
this.age = age;
}
}
but this is correct, why
class Person{
final String name;
final int age;
// Correct
Person(String name, int age): this.name = name, this.age = age;
}