You will see I need to save the data of a list of items in SQFlite, I am doing it with this procedure
void cargarusuarios() {
res.forEach((cliente) {
usuario.usuario = cliente[0].toString();
usuario.telefono = cliente[1].toString();
usuario.fechaexpira = cliente[2].toString();
usuario.email = cliente[3].toString();
usuario.plan = cliente[4].toString();
usuario.conexiones = cliente[5].toString();
DBProvider.db.nuevoUsuario(usuario);
});
}
The problem is, the save procedure is executed correctly according to the number of clients, but in all of them only the information corresponding to the last one is saved.
I would think that in each of the steps it would save the information of that iteration and in the following ones it would act in the same way.
What happens is that it
nuevoUsuario
is asynchronous, try usingFuture.forEach
so that it waits for each request to finish.