Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.68 KB | None | 0 0
  1. return StreamBuilder<QuerySnapshot>(
  2.       stream: communityBloc.feedStream,
  3.       builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
  4.         if (snapshot.hasError) {
  5.           debugPrint('Snapshot error: ${snapshot.error}');
  6.           return Text('error');
  7.         }
  8.         if (snapshot.connectionState == ConnectionState.none)
  9.           return Text('stream is null, connection = none');
  10.         if (snapshot.connectionState == ConnectionState.waiting)
  11.           return UIUtils.Spinner();
  12.         if (snapshot.data == null || snapshot.data.documents.length == 0) {
  13.           return Text('no data');
  14.         }
  15.         return Provider(
  16.           builder: (_) => ActivityPreviewBloc(
  17.               Provider.of<AuthenticationBloc>(context).authenticatedUserUID),
  18.           dispose: (_, bloc) => bloc.dispose(),
  19.           child: ListView.builder(
  20.             addAutomaticKeepAlives: true, // TODO review this
  21.             itemBuilder: (context, index) => ActivityPreview(
  22.               Activity.fromJson(
  23.                 Provider.of<GlobalBloc>(context),
  24.                 snapshot.data.documents[index].data
  25.                   ..addEntries([
  26.                     MapEntry(
  27.                       'activity_id',
  28.                       snapshot.data.documents[index].documentID,
  29.                     )
  30.                   ]),
  31.               ),
  32.             ),
  33.             itemCount: snapshot.data.documents.length,
  34.           ),
  35.         );
  36.       },
  37.     );
  38.  
  39.  
  40. Stream<QuerySnapshot> get feedStream {
  41.     Stream<QuerySnapshot> activities = _firestore
  42.         .collection('activities')
  43.         .orderBy('timestamp', descending: true)
  44.         .snapshots();
  45.     return activities;
  46.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement