streamData method

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

Implementation

@override
Widget streamData({
  required String collectionId,
  required Widget Function(List<Map<String, dynamic>> resultList) consumerFunc,
  required Map<String, dynamic> where,
  required String orderBy,
  bool descending = true,
  int? limit, // 페이지 크기
  bool hasPage = false,
}) {
  final stream = initStream(collectionId: collectionId, where: where, orderBy: orderBy);
  // Query<Object?> queryRef = fromRef; // Query 타입으로 초기화

  // 여러 조건이 주어진 경우 where 조건을 추가
  // where.forEach((fieldName, fieldValue) {
  //   queryRef = queryRef.where(fieldName, isEqualTo: fieldValue.value);
  // });

  return StreamBuilder<List<Map<String, dynamic>>>(
    stream: stream,
    builder: (context, snapshot) {
      if (snapshot.hasError) {
        return Text('Error: ${snapshot.error}');
      }
      switch (snapshot.connectionState) {
        case ConnectionState.waiting:
          return const Text('Loading...');
        default:
          logger.finest('streamData :  ${snapshot.data!.length} data founded');

          // // 마지막 문서 업데이트 (페이징을 위해)
          // if (hasPage) {
          //   startAfter = snapshot.data!.isNotEmpty ? snapshot.data!.last : null;
          // }

          return consumerFunc(filterSnapshotData(snapshot.data!, where));
      }
    },
  );
}