$query<R extends FirestoreEntity<R>> method

Future<List<R>> $query<R extends FirestoreEntity<R>>({
  1. Query<R> query(
    1. Query<R> query
    )?,
  2. R? startAfter,
  3. R? endBefore,
  4. R? startAt,
  5. R? endAt,
})

Returns all R entities in the corresponding subcollection of this entity matching the query.

Implementation

Future<List<R>> $query<R extends FirestoreEntity<R>>(
    {Query<R> Function(Query<R> query)? query,
    R? startAfter,
    R? endBefore,
    R? startAt,
    R? endAt}) async {
  var subCollection = getSubCollection<R>();
  Query<R> q = subCollection;
  if (query != null) {
    q = query(q);
  }

  // Cursor start
  if (startAfter != null) {
    q = q.startAfterDocument(await startAfter.snapshot());
  } else if (startAt != null) {
    q = q.startAtDocument(await startAt.snapshot());
  }

  // Cursor end
  if (endBefore != null) {
    q = q.endBeforeDocument(await endBefore.snapshot());
  } else if (endAt != null) {
    q = q.endAtDocument(await endAt.snapshot());
  }
  var snapshot = await q.get();
  return snapshot.docs.map((e) => e.data()).toList();
}