undefined_constructor_in_initializer
The class '{0}' doesn't have a constructor named '{1}'.
The class '{0}' doesn't have an unnamed constructor.
Description
#The analyzer produces this diagnostic when a superclass constructor is invoked in the initializer list of a constructor, but the superclass doesn't define the constructor being invoked.
Examples
#The following code produces this diagnostic because A
doesn't have an
unnamed constructor:
class A {
A.n();
}
class B extends A {
B() : super();
}
The following code produces this diagnostic because A
doesn't have a
constructor named m
:
class A {
A.n();
}
class B extends A {
B() : super.m();
}
Common fixes
#If the superclass defines a constructor that should be invoked, then change the constructor being invoked:
class A {
A.n();
}
class B extends A {
B() : super.n();
}
If the superclass doesn't define an appropriate constructor, then define the constructor being invoked:
class A {
A.m();
A.n();
}
class B extends A {
B() : super.m();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。