redirect_generative_to_non_generative_constructor
Generative constructors can't redirect to a factory constructor.
Description
#The analyzer produces this diagnostic when a generative constructor redirects to a factory constructor.
Example
#The following code produces this diagnostic because the generative constructor C.a
redirects to the factory constructor C.b
:
class C {
C.a() : this.b();
factory C.b() => C.a();
}
Common fixes
#If the generative constructor doesn't need to redirect to another constructor, then remove the redirect.
class C {
C.a();
factory C.b() => C.a();
}
If the generative constructor must redirect to another constructor, then make the other constructor be a generative (non-factory) constructor:
class C {
C.a() : this.b();
C.b();
}
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.