Skip to main content

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:

dart
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:

dart
enum E {
  a(1), b(2);

  const E(this.i);

  final int i;
}

Common fixes

#

Remove the unnecessary keyword:

dart
enum E(final int i) {
  a(1), b(2);
}
dart
enum E {
  a(1), b(2);

  E(this.i);

  final int i;
}