SHARE
TWEET

Untitled

a guest Jun 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MessageList extends StatelessWidget {
  2.  MessageList({this.firestore});
  3.  
  4.  final Firestore firestore;
  5.  
  6.  @override
  7.  Widget build(BuildContext context) {
  8.  return StreamBuilder<QuerySnapshot>(
  9.   stream: firestore.collection('messages').snapshots(),
  10.   builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
  11.     if (!snapshot.hasData) return const Text('Loading...');
  12.     final int messageCount = snapshot.data.documents.length;
  13.     return ListView.builder(
  14.       itemCount: messageCount,
  15.       itemBuilder: (_, int index) {
  16.         final DocumentSnapshot document = snapshot.data.documents[index];
  17.         return ListTile(
  18.           title: Text(document['message'] ?? '<No message retrieved>'),
  19.           subtitle: Text('Message ${index + 1} of $messageCount'),
  20.         );
  21.       },
  22.     );
  23.   },
  24.  );
  25.  }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top