Search code examples
flutterstream-builderflutter-futurebuilder

how to display properly single value from a StreamBuilder 'Cloud Firestore'


i have data stored in filds like so => image

i have followed the documentation, the data just refuses to show for some reason.

it looks somthing like this

StreamBuilder(
                  stream:
                      FirebaseFirestore.instance.collection('users').snapshots(),
                  builder: (context, snapshot) {....}
     )

and then

 if (snapshot.connectionState == ConnectionState.active) {
                  print(snapshot.data.documents[0]['User Email']); 
....}

note: the stream works fine but im assuming this happening coz of the way im calling it the snapshot.data.documents

how can i properly call them ?


Solution

  • I think it is because of the [0]. When you read just one of the documents, refer to:

    FirebaseFirestore.instance.collection('users').doc('yourDocument').snapshots();
    

    and if you will read more then one you can use this:

     CollectionReference users = FirebaseFirestore.instance.collection('users');
    
        return new ListView(
          children: snapshot.data.documents.map((DocumentSnapshot document) {
            return new ListTile(
              title: new Text(document.data()['full_name']),
              subtitle: new Text(document.data()['company']),
            );
          }).toList(),
        );