Is it possible to use the enum constructor directly?
void main() {
print(Test(1));
}
enum Test {
test1(1),
test2(2);
final int id;
const Test(this.id);
}
This will give the following error:
generative enum constructors can only be used as targets of redirection
I know that it can be solved like this:
enum Test {
test1(1),
test2(2);
final int id;
const Test(this.id);
factory Test.fromId(int id) {
return values.firstWhere((e) => e.id == id);
}
}
But it feels like there must be a way to avoid this boiler plate factory?