conflicting_constructor_and_static_member
'{0}' can't be used to name both a constructor and a static field in this class.
'{0}' can't be used to name both a constructor and a static getter in this class.
'{0}' can't be used to name both a constructor and a static method in this class.
'{0}' can't be used to name both a constructor and a static setter in this class.
Description
#The analyzer produces this diagnostic when a named constructor and either a static method or static field have the same name. Both are accessed using the name of the class, so having the same name makes the reference ambiguous.
Examples
#The following code produces this diagnostic because the static field foo
and the named constructor foo
have the same name:
class C {
C.foo();
static int foo = 0;
}
The following code produces this diagnostic because the static method foo
and the named constructor foo
have the same name:
class C {
C.foo();
static void foo() {}
}
Common fixes
#除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。