getDataFromQuery<T> function

Stream<List<T>> getDataFromQuery <T>({Query query, DocumentMapper<T> mapper, List<ItemFilter<T>> clientSitefilters, ItemComparer<T> orderComparer })

Convenience Method to access the data of a Query as a stream while applying a mapping function on each document with optional client side filtering and sorting qery : the data source mapper : mapping function that gets applied to every document in the query. Typically used to deserialize the Map returned from FireStore clientSideFilters : optional list of filter functions that execute a .where() on the result on the client side orderComparer : optional comparisson function. If provided your resulting data will be sorted based on it on the client

Implementation

Stream<List<T>> getDataFromQuery<T>({
  Query query,
  DocumentMapper<T> mapper,
  List<ItemFilter<T>> clientSitefilters,
  ItemComparer<T> orderComparer,
}) {
  return query.snapshots().map((snapShot) {
    Iterable<T> items = snapShot.documents.map(mapper);
    if (clientSitefilters != null) {
      for (var filter in clientSitefilters) {
        items = items.where(filter);
      }
    }
    var asList = items.toList();
    if (orderComparer != null) {
      asList.sort(orderComparer);
    }
    return asList;
  });
}