non_generative_constructor
The generative constructor '{0}' is expected, but a factory was found.
Description
#The analyzer produces this diagnostic when the initializer list of a constructor invokes a constructor from the superclass, and the invoked constructor is a factory constructor. Only a generative constructor can be invoked in the initializer list.
Example
#The following code produces this diagnostic because the invocation of the
constructor super.one()
is invoking a factory constructor:
dart
class A {
factory A.one() = B;
A.two();
}
class B extends A {
B() : super.one();
}
Common fixes
#Change the super invocation to invoke a generative constructor:
dart
class A {
factory A.one() = B;
A.two();
}
class B extends A {
B() : super.two();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。