0

Good evening guys, I don't usually comment here, but I really have a serious problem, so let me put it in context: I have a foreach that runs through a map, all good until it reaches a key in which it has to make a call to a rest api(the calls work without problem), when I tell it that it has to wait for that result with an "await", the loop keeps running without stopping in the await, so that when the await returns there is an error in the execution due to unforeseen events.

Translated with www.DeepL.com/Translator (free version) I attach the code of the foreach:

 datosPeticiones.forEach((clave, valor) async {
        switch (clave) {
          case "descripcionPublicacion":
            if (valor != null && valor != "") {
              publicacionModelo.setDescripcionPublicacion = valor;
            } else {
              publicacionModelo.setDescripcionPublicacion = "Sin Descripción";
            }

           break;


case "publicacionComentarios":
            for (int i = 0; i < valor.length;) {
              for (int j = 0; j < valor.length;) {
                if (datosPeticiones["publicacionValoraciones"][j]["userId"] ==
                    datosPeticiones["publicacionComentarios"][i]["userId"]) {
                  try {
                    var peticionUsuario = await super.cliente.get(
                        Uri.parse(
                            "${super.apiUrl}/api/UserProfiles?loginId=${datosPeticiones["publicacionValoraciones"][j]["userId"]}"),
                        headers: cabeceraGET);
                    print(peticionUsuario.body);
                  } catch (e) {
                    print(e);
                  }
                }
                j++;
              }
              i++;
            }

            break;

I have to return a response from which I will get information to use for painting later, but I can't get it to stop on the await.

0 Answers0