Skip to main content

avoid-unnecessary-constructor

has auto-fix
pro+

Suggests removing an unnecessary empty constructor for enum and class declarations.

In Dart, classes and enums always have an implicit default constructor and declaring it explicitly is usually unnecessary.

Example

❌ Bad:

class SomeClass {
final values = <int>{};

// LINT: This constructor is unnecessary. Try removing it.
SomeClass();
}

enum MyEnum {
alpha,
beta,
gama;

// LINT: This constructor is unnecessary. Try removing it.
const MyEnum();
}

✅ Good:

class SomeClass {
final values = <int>{};
}

enum MyEnum {
alpha,
beta,
gama;
}