initStream method

  1. @override
dynamic initStream({
  1. required String collectionId,
  2. required Map<String, dynamic> where,
  3. required String orderBy,
  4. bool descending = true,
  5. int? limit,
  6. bool hasPage = false,
})
override

Implementation

@override
dynamic initStream({
  required String collectionId,
  required Map<String, dynamic> where,
  required String orderBy,
  bool descending = true,
  int? limit, // 페이지 크기
  bool hasPage = false,
}) {
  if (_db == null) {
    return const Text('database is not initialized');
  }
  CollectionReference? collectionRef = _db!.collection(collectionId);

  Query<Object?> query = collectionRef.orderBy(orderBy, descending: descending);
  where.forEach((mid, value) {
    query = query.where(mid, isEqualTo: value.value);
  });

  // 마지막 문서가 있으면, 해당 문서 이후부터 데이터 로드
  if (limit != null) {
    query = query.limit(limit);
  }
  if (startAfter != null && hasPage) {
    query = query.startAfterDocument(startAfter!);
  }
  return query.snapshots();
}