enum_ constant_ with_ non_ const_ constructor
Details about the 'enum_constant_with_non_const_constructor' diagnostic produced by the Dart analyzer.
The invoked constructor isn't a 'const' constructor.
Description
#
The analyzer produces this diagnostic when an enum value is being created
using either a factory constructor or a generative constructor that isn't
marked as being const.
Example
#
The following code produces this diagnostic because the enum value e is
being initialized by a factory constructor:
enum E {
e();
factory E() => e;
}
Common fixes
#Use a generative constructor marked as const:
enum E {
e._();
factory E() => e;
const E._();
}
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.