invalid_annotation
Annotation must be either a const variable reference or const constructor invocation.
Description
#The analyzer produces this diagnostic when an annotation is found that is
using something that is neither a variable marked as const
or the
invocation of a const
constructor.
Getters can't be used as annotations.
Examples
#The following code produces this diagnostic because the variable v
isn't
a const
variable:
var v = 0;
@v
void f() {
}
The following code produces this diagnostic because f
isn't a variable:
@f
void f() {
}
The following code produces this diagnostic because f
isn't a
constructor:
@f()
void f() {
}
The following code produces this diagnostic because g
is a getter:
@g
int get g => 0;
Common fixes
#If the annotation is referencing a variable that isn't a const
constructor, add the keyword const
to the variable's declaration:
const v = 0;
@v
void f() {
}
If the annotation isn't referencing a variable, then remove it:
int v = 0;
void f() {
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。