new_with_undefined_constructor_default
The class '{0}' doesn't have an unnamed constructor.
Description
#The analyzer produces this diagnostic when an unnamed constructor is invoked on a class that defines named constructors but the class doesn't have an unnamed constructor.
Example
#The following code produces this diagnostic because A
doesn't define an unnamed constructor:
class A {
A.a();
}
A f() => A();
Common fixes
#If one of the named constructors does what you need, then use it:
class A {
A.a();
}
A f() => A.a();
If none of the named constructors does what you need, and you're able to add an unnamed constructor, then add the constructor:
class A {
A();
A.a();
}
A f() => 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.