Hello, I'm new to flutter, I'm trying to make get requests with a value entered in a text box, then when I press the button I do with this method:
getDataPorArea('BuscarRegistroEmbarques', _ot);
The method to extract the information with the Future is:
Future getDataPorArea(area, ot) async {
const _baseUrl = 'servidor';
final url = Uri.http(_baseUrl, 'api/Actualizacion/$area/$ot');
final rsp = await http.get(url);
final List<dynamic> dataList = json.decode(rsp.body);
if (dataList.first == 0) {
print("Sin Datos");
return registroSinDatosFromJson(dataList.toString());
} else {
print("Con datos");
return buscarRegistroFromJson(rsp.body);
}
}
When printing to the console I only get the following:
I/flutter (25996): caso calidad
I/flutter (25996):
I/flutter (25996): Sin Datos
but if I press the button again
I/flutter (25996): caso calidad
I/flutter (25996): [0]
I/flutter (25996): Sin Datos
I don't know how to do it in a way that can delay printing the variable
According to the comments, what you want to do is access the attributes returned by the
json
, it is good that you always validate that the response of the call to the service is 200, so you will have to validate that first, thenList<dynamic>
we replace it with aList<Map<String, dynamic>>
because it that returns the json is a list of maps:I hope and that answer helps you