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:
dart
class A {
A.a();
}
A f() => A();
Common fixes
#If one of the named constructors does what you need, then use it:
dart
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:
dart
class A {
A();
A.a();
}
A f() => A();
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。