Home > Enterprise >  how to display documents firestoredatabase in home screen flutter
how to display documents firestoredatabase in home screen flutter

Time:05-16

I want to display the documents in Firestore database in home screen by using snapshot

I need something like this

Text('documents["name"]')

enter image description here

CodePudding user response:

     body: new StreamBuilder(
        stream: Firestore.instance.collection("groups").snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return Text(
              'No Data...',
            );
          } else { 
              <DocumentSnapshot> items = snapshot.data.documents;
              return Text(items[0]["name"]);
          }

CodePudding user response:

Use this code:

List<String> _groupsId = [];

await fireStore
    .collection('groups')
    .get()
    .then((QuerySnapshot querySnapshot) {
  for (var doc in querySnapshot.docs) {
    _groupsId.add(doc.id);
  }
});

You will get all list key of documents

  • Related