跳到主要內容

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._();
}