File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
packages/firebase_snippets_app/lib/widgets Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:cloud_firestore/cloud_firestore.dart' ;
2
+ import 'package:flutter/material.dart' ;
3
+
4
+ // [START listen_to_realtime_updates_listen_for_updates2]
5
+ class UserInformation extends StatefulWidget {
6
+ @override
7
+ _UserInformationState createState () => _UserInformationState ();
8
+ }
9
+
10
+ class _UserInformationState extends State <UserInformation > {
11
+ final Stream <QuerySnapshot > _usersStream =
12
+ FirebaseFirestore .instance.collection ('users' ).snapshots ();
13
+
14
+ @override
15
+ Widget build (BuildContext context) {
16
+ return StreamBuilder <QuerySnapshot >(
17
+ stream: _usersStream,
18
+ builder: (BuildContext context, AsyncSnapshot <QuerySnapshot > snapshot) {
19
+ if (snapshot.hasError) {
20
+ return const Text ('Something went wrong' );
21
+ }
22
+
23
+ if (snapshot.connectionState == ConnectionState .waiting) {
24
+ return const Text ("Loading" );
25
+ }
26
+
27
+ return ListView (
28
+ children: snapshot.data! .docs
29
+ .map ((DocumentSnapshot document) {
30
+ Map <String , dynamic > data =
31
+ document.data ()! as Map <String , dynamic >;
32
+ return ListTile (
33
+ title: Text (data['full_name' ]),
34
+ subtitle: Text (data['company' ]),
35
+ );
36
+ })
37
+ .toList ()
38
+ .cast (),
39
+ );
40
+ },
41
+ );
42
+ }
43
+ }
44
+ // [EMD listen_to_realtime_updates_listen_for_updates2]
You can’t perform that action at this time.
0 commit comments