invalid_annotation_constant_value_from_deferred_library
Constant values from a deferred library can't be used in annotations.
Description
#The analyzer produces this diagnostic when a constant defined in a library that is imported as a deferred library is referenced in the argument list of an annotation. Annotations are evaluated at compile time, and values from deferred libraries aren't available at compile time.
For more information, check out Lazily loading a library.
Example
#The following code produces this diagnostic because the constant pi
is
being referenced in the argument list of an annotation, even though the
library that defines it is being imported as a deferred library:
import 'dart:math' deferred as math;
class C {
const C(double d);
}
@C(math.pi)
void f () {}
Common fixes
#If you need to reference the imported constant, then remove the deferred
keyword:
import 'dart:math' as math;
class C {
const C(double d);
}
@C(math.pi)
void f () {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。