streamData2 method

  1. @override
Widget streamData2({
  1. required dynamic snapshot,
  2. required Widget consumerFunc(
    1. List<Map<String, dynamic>> resultList
    ),
  3. bool hasPage = false,
})
override

Implementation

@override
Widget streamData2({
  required dynamic snapshot,
  required Widget Function(List<Map<String, dynamic>> resultList) consumerFunc,
  bool hasPage = false,
}) {
  // appwrite 에서는 일단은 ...사용되지 않는다.
  return StreamBuilder<QuerySnapshot>(
    stream: snapshot,
    builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> 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!.docs.length} data founded');

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

          return consumerFunc(snapshot.data!.docs.map((doc) {
            return doc.data() as Map<String, dynamic>;
          }).toList());
      }
    },
  );
}