duplicate_constructor
The constructor with name '{0}' is already defined.
The unnamed constructor is already defined.
Description
#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();
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.