instantiate_enum
Enums can't be instantiated.
Description
#The analyzer produces this diagnostic when an enum is instantiated. It's invalid to create an instance of an enum by invoking a constructor; only the instances named in the declaration of the enum can exist.
Example
#The following code produces this diagnostic because the enum E
is being
instantiated:
dart
// @dart = 2.16
enum E {a}
var e = E();
Common fixes
#If you intend to use an instance of the enum, then reference one of the constants defined in the enum:
dart
// @dart = 2.16
enum E {a}
var e = E.a;
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。