Skip to main content

avoid-unnecessary-constructor

added in: 1.22.0
🛠
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>{};

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

enum MyEnum {
alpha,
beta,
gama;

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

✅ Good:

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

enum MyEnum {
alpha,
beta,
gama;
}