non_generative_implicit_constructor
The unnamed constructor of superclass '{0}' (called by the default constructor of '{1}') must be a generative constructor, but factory found.
Description
#The analyzer produces this diagnostic when a class has an implicit generative constructor and the superclass has an explicit unnamed factory constructor. The implicit constructor in the subclass implicitly invokes the unnamed constructor in the superclass, but generative constructors can only invoke another generative constructor, not a factory constructor.
Example
#The following code produces this diagnostic because the implicit constructor in B
invokes the unnamed constructor in A
, but the constructor in A
is a factory constructor, when a generative constructor is required:
class A {
factory A() => throw 0;
A.named();
}
class B extends A {}
Common fixes
#If the unnamed constructor in the superclass can be a generative constructor, then change it to be a generative constructor:
class A {
A();
A.named();
}
class B extends A { }
If the unnamed constructor can't be a generative constructor and there are other generative constructors in the superclass, then explicitly invoke one of them:
class A {
factory A() => throw 0;
A.named();
}
class B extends A {
B() : super.named();
}
If there are no generative constructors that can be used and none can be added, then implement the superclass rather than extending it:
class A {
factory A() => throw 0;
A.named();
}
class B implements A {}
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.