I have a class with an immutable property, int id. How do I pass the value of id to the constructor?
class Hey
{
var val;
final int id;
Hey(int id,var val)
{
this.id=id;
this.val=val;
}
}
void main()
{
Hey hey=new Hey(0,1);
}
hey.dart:10:10: Error: Setter not found: 'id'. this.id=id; ^^ hey.dart:10:10: Error: The setter 'id' isn't defined for the class 'Hey'. - 'Hey' is from 'hey.dart'. Try correcting the name to the name of an existing setter, or defining a setter or field named 'id'. this.id=id; ^^
I don't think a setter is required for a const or final field property. The API is not clear on how to handle this.