Dart Analyze logoDart Analyze/
DRT-W1303

Constructor already definedDRT-W1303

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when a class declares more than one unnamed constructor or when it declares more than one constructor with the same name.

Examples

The following code produces this diagnostic because there are two declarations for the unnamed constructor:

class C {
  C();

  C();
}

The following code produces this diagnostic because there are two declarations for the constructor named m:

class C {
  C.m();

  C.m();
}

Common fixes

If there are multiple unnamed constructors and all of the constructors are needed, then give all of them, or all except one of them, a name:

class C {
  C();

  C.n();
}

If there are multiple unnamed constructors and all except one of them are unneeded, then remove the constructors that aren't needed:

class C {
  C();
}

If there are multiple named constructors and all of the constructors are needed, then rename all except one of them:

class C {
  C.m();

  C.n();
}

If there are multiple named constructors and all except one of them are unneeded, then remove the constructors that aren't needed:

class C {
  C.m();
}