Skip to main content

multiple_primary_constructor_body_declarations

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

Only one primary constructor body declaration is allowed.

Description

#

The analyzer produces this diagnostic when a class that declares a primary constructor also has more than one primary constructor body.

Example

#

The following code produces this diagnostic because the class C has more than one primary constructor body:

dart
class C(final int x) {
  this : assert(x >= 0);

  this : assert(x <= 0);
}

Common fixes

#

Remove all but one of the primary constructor bodies, possibly by merging them:

dart
class C(final int x) {
  this : assert(x >= 0), assert(x <= 0);
}