unnecessary_ const_ in_ enum_ constructor
Details about the 'unnecessary_const_in_enum_constructor' diagnostic produced by the Dart analyzer.
Unnecessary 'const' keyword in an enum constructor.
Description
#
The analyzer produces this diagnostic when the keyword const is used in
a generative enum constructor. Generative enum constructors are implicitly
const.
Examples
#
The following code produces this diagnostic because the keyword const in
the enum's primary constructor isn't needed:
enum const E(final int i) {
a(1), b(2);
}
The following code produces this diagnostic because the keyword const in
the enum's secondary constructor isn't needed:
enum E {
a(1), b(2);
const E(this.i);
final int i;
}
Common fixes
#Remove the unnecessary keyword:
enum E(final int i) {
a(1), b(2);
}
enum E {
a(1), b(2);
E(this.i);
final int i;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.