Home > database >  Read firebase doc and copy the data into dart list
Read firebase doc and copy the data into dart list

Time:09-01

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

my firebase docs

CodePudding user response:

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
        
      }
    });

CodePudding user response:

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);

  • Related