跳到主要内容

enum_constant_with_non_const_constructor

调用的构造函数不是“const”构造函数。

描述

#

当使用工厂构造函数或未标记为 const 的生成式构造函数创建枚举值时,分析器会生成此诊断信息。

示例

#

以下代码会生成此诊断信息,因为枚举值 e 由工厂构造函数初始化

dart
enum E {
  e();

  factory E() => e;
}

常见修复方案

#

使用标记为 const 的生成式构造函数

dart
enum E {
  e._();

  factory E() => e;

  const E._();
}