Skip to main content

unnecessary_primary_constructor_body

Details about the 'unnecessary_primary_constructor_body' diagnostic produced by the Dart analyzer.

Unnecessary primary constructor body.

Description

#

The analyzer produces this diagnostic when a primary constructor body has no initializers, body, annotations, or documentation comment. Without these, the body is unnecessary.

Example

#

The following code produces this diagnostic because the primary constructor body is unnecessary:

dart
class C(final int i) {
  this;
}

Common fixes

#

Remove the primary constructor body:

dart
class C(final int i);