0

I want to retrieve data of an array that stores url's and place them, each one, in an item in a list. In my example, all url's are stored in the first item. Is there a way to manipulate the field indexes todo this? [https://i.stack.imgur.com/KnIF6.png][1]. Here's my code:

Future<void> getImages() async {
  int i = 0;
  listImgs = List(4);

  await firestoreInstance
      .collection('dados_inst')
      .where('cod_inst', isEqualTo: codInst)
      .get()
      .then((value) {
    value.docs.forEach((snapshot) {
      listImgs[i++] = snapshot.get('list_view');
    });
  });
  for (i = 0; i < 4; i++) {
    print(listImgs[i]);
  }
}

Marc Niet
  • 13
  • 2

1 Answers1

0

A simple way is to convert the value.docs list to a map, and use the forEach method of that, which gets both the index and the value:

value.docs.asMap().forEach((index, snapshot) {
  listImgs[index] = snapshot.get('list_view');
});

See also:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807