getAllFieldsWithEntityAnnotation<T extends EntityAnnotation> method

Map<String, List<T>> getAllFieldsWithEntityAnnotation<T extends EntityAnnotation>([
  1. O? o,
  2. bool filter(
    1. T e
    )?
])

Implementation

Map<String, List<T>>
    getAllFieldsWithEntityAnnotation<T extends EntityAnnotation>(
        [O? o, bool Function(T e)? filter]) {
  var annotations = getAllFieldsEntityAnnotations(o);
  if (annotations == null) return {};

  var entries = annotations.entries;

  Iterable<MapEntry<String, List<T>>> entriesTyped;

  if (filter != null) {
    entriesTyped = entries.map((e) =>
        MapEntry(e.key, e.value.whereType<T>().where(filter).toList()));
  } else {
    entriesTyped =
        entries.map((e) => MapEntry(e.key, e.value.whereType<T>().toList()));
  }

  entriesTyped = entriesTyped.where((e) => e.value.isNotEmpty);

  return entriesTyped.toMapFromEntries();
}