redirect_to_non_class
The name '{0}' isn't a type and can't be used in a redirected constructor.
Description
#One way to implement a factory constructor is to redirect to another constructor by referencing the name of the constructor. The analyzer produces this diagnostic when the redirect is to something other than a constructor.
Example
#The following code produces this diagnostic because f
is a function:
C f() => throw 0;
class C {
factory C() = f;
}
Common fixes
#If the constructor isn't defined, then either define it or replace it with a constructor that is defined.
If the constructor is defined but the class that defines it isn't visible, then you probably need to add an import.
If you're trying to return the value returned by a function, then rewrite the constructor to return the value from the constructor's body:
C f() => throw 0;
class C {
factory C() => f();
}
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.