0
What’s wrong with my function? Because, the data called in the second api returns with enough delay.
How do I load the screen only after the return of the second API?
var os = new List<OS>();
_getOs() {
API.getOS().then((response) {
setState(() {
Map<String, dynamic> data = json.decode(response.body);
os = List<OS>.from(data['registros'].map((x) => OS.fromJson(x)));
for (var i = 0; i < os.length; i++) {
API.getCliente(os[i].idCliente).then((response) {
var clies = new List<Cliente>();
Map<String, dynamic> dataCli = json.decode(response.body);
clies = List<Cliente>.from(
dataCli['registros'].map((x) => Cliente.fromJson(x)));
os[i].nomeCliente = clies[0].fantasia;
});
}
});
});
}