non_constant_annotation_constructor
Annotation creation can only call a const constructor.
Description
#The analyzer produces this diagnostic when an annotation is the invocation of an existing constructor even though the invoked constructor isn't a const constructor.
Example
#The following code produces this diagnostic because the constructor for C
isn't a const constructor:
dart
@C()
void f() {
}
class C {
C();
}
Common fixes
#If it's valid for the class to have a const constructor, then create a const constructor that can be used for the annotation:
dart
@C()
void f() {
}
class C {
const C();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。