invalid_annotation_from_deferred_library
Constant values from a deferred library can't be used as annotations.
Description
#The analyzer produces this diagnostic when a constant from a library that is imported using a deferred import is used as an annotation. Annotations are evaluated at compile time, and constants 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 used as an annotation when the library dart:math
is imported as
deferred
:
import 'dart:math' deferred as math;
@math.pi
void f() {}
Common fixes
#If you need to reference the constant as an annotation, then remove the
keyword deferred
from the import:
import 'dart:math' as math;
@math.pi
void f() {}
If you can use a different constant as an annotation, then replace the annotation with a different constant:
@deprecated
void f() {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。