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 in-body 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);
new(this.i);
final int i;
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.