firstMetadataOfType<T> function

T? firstMetadataOfType<T>(
  1. DeclarationMirror dm, {
  2. TypeMirror? dynamicType,
})

Implementation

T? firstMetadataOfType<T>(DeclarationMirror dm, {TypeMirror? dynamicType}) {
  final tMirror = dynamicType ?? reflectType(T);
  try {
    return dm.metadata
        .firstWhere((im) => im.type.isSubtypeOf(tMirror))
        .reflectee as T;
  } on StateError {
    return null;
  }
}