getAnnotation<AnnotationType> static method
DartObject?
getAnnotation<AnnotationType>(
- Element element
Implementation
static DartObject? getAnnotation<AnnotationType>(Element element) {
final annotations = TypeChecker.fromRuntime(AnnotationType).annotationsOf(element);
if (annotations.isEmpty) {
return null;
}
if (annotations.length > 1) {
throw Exception('You tried to add multiple @$AnnotationType() annotations to the '
"same element (${element.name}), but that's not possible.");
}
return annotations.single;
}