undefined_enum_constructor
The enum doesn't have a constructor named '{0}'.
The enum doesn't have an unnamed constructor.
Description
#The analyzer produces this diagnostic when the constructor invoked to initialize an enum value doesn't exist.
Examples
#The following code produces this diagnostic because the enum value c
is being initialized by the unnamed constructor, but there's no unnamed
constructor defined in E
:
enum E {
c();
const E.x();
}
The following code produces this diagnostic because the enum value c
is
being initialized by the constructor named x
, but there's no constructor
named x
defined in E
:
enum E {
c.x();
const E.y();
}
Common fixes
#If the enum value is being initialized by the unnamed constructor and one of the named constructors should have been used, then add the name of the constructor:
enum E {
c.x();
const E.x();
}
If the enum value is being initialized by the unnamed constructor and none of the named constructors are appropriate, then define the unnamed constructor:
enum E {
c();
const E();
}
If the enum value is being initialized by a named constructor and one of the existing constructors should have been used, then change the name of the constructor being invoked (or remove it if the unnamed constructor should be used):
enum E {
c.y();
const E();
const E.y();
}
If the enum value is being initialized by a named constructor and none of the existing constructors should have been used, then define a constructor with the name that was used:
enum E {
c.x();
const E.x();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。