query<T extends FirestoreEntity<T>> static method

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

Implementation

static Future<List<T>> query<T extends FirestoreEntity<T>>(
    {Query<T> Function(Query<T> query)? query,
    T? startAfter,
    T? endBefore,
    T? startAt,
    T? endAt}) async {
  var collection = DogFirestoreEngine.instance.collection<T>();
  Query<T> q = collection;
  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();
}