skip to Main Content

How can I read the data of my Firebase document and put the data in a local list/array?

my firebase docs

2

Answers


  1. To get all data from Firestore.

    FirebaseFirestore.instance
            .collection("users")
            .get()
            .then((value) {
          print(value.docs);
          for (var element in value.docs) {
            print(element.id);// you will get all ids here
            
          }
        });
    

    If you want to upload one particular data from Firestore.

    FirebaseFirestore.instance
            .collection("users")
            
            .where("uid",
                isEqualTo: 'your_uid')
            .get()
            .then((value) {
          print(value.docs);
          for (var element in value.docs) {
            print(element.id); // single id of that collection
            
          }
        });
    
    Login or Signup to reply.
  2. I have tried this once….
    check if this is the same u looking for

    
    List<String> list=[];
        final snapshot = await FirebaseFirestore.instance
            .collection("users").get();
    
        for(int x=0;x<snapshot.docs.length;x++)
          {
            list.add(snapshot.docs[x].id);
          }
        print(list);
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search