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();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。