Ive been trying to get this right for some time and can\'t figure out what is wrong.
enum MyEnum { a, b }
class ClassA {
final MyEnum myEnum;
ClassA({th
For ClassA to be able to create constant values, the constructor must be marked as const.
enum MyEnum { a, b }
class ClassA {
final MyEnum myEnum;
const ClassA({this.myEnum = MyEnum.a}); // <- constructor is const.
}
class ClassB {
final ClassA classA;
ClassB({this.classA = const ClassA()}); // <- creation is const
}
You need to write const for the object creation, even if only constant values are allowed as default values. The language do not automatically insert a const in that position because the language team wants to reserve the option of allowing non-constant default values at some point.