0

I have returned all the IDs of my firestore documents, and now I need to get the index of each one. Until now I get an error: "Spread elements in a list or set literals must implement 'Iterable' " So, How can I iterate over it?

FirebaseFirestore.instance
    .collection('prova')
    .get()
    .then((QuerySnapshot querySnapshot) {
  querySnapshot.docs.forEach((doc) {
    print(doc.id);
     //this next line gives me error
    var a = <String>{...doc.id};
    print(a);

  });
});

Output:

I/flutter (29392): G0luyVnh1ahW5bfSqh8k
I/flutter (29392): V7ts6hEYqQiM4creal1O
I/flutter (29392): Xf3zzLzBzF3dzQ4OT9oO
I/flutter (29392): iKSjc3HQCAvzmaCMpFcg
I/flutter (29392): jxHT2TwMTfRf8SjbidK2

enter image description here

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
Giovanni
  • 512
  • 2
  • 6
  • 23
  • are you trying to print the JSON contet of each document? – Gwhyyy Nov 15 '22 at 22:24
  • No, i would like to iterate the array of IDs, with a for loop, or anything so i can get the index of each ID. – Giovanni Nov 16 '22 at 07:58
  • Have you gone through this stackoverflow [link1] (https://stackoverflow.com/questions/61065524/use-spread-operator-on-object-with-type-safety-in-dart) – Sathi Aiswarya Nov 16 '22 at 14:44

0 Answers0