1
I’m having trouble dealing with the return of a REST request.
API: Rails is working properly.
my job
Future <Map> _getProdPromo() async {
http.Response response = await http.get("http://10.0.2.2:3000/infoPromocao.json");
List responseJson = json.decode(response.body);
return json.decode(response.body);
}
To test Console Print.
@override
void initState() {
super.initState();
_getProdPromo().then((map){
print(map);
});
}
Error:
flutter (19914): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'List' is not a subtype of type 'Futureor>' E/flutter (19914): #0
_Productsfromocionaisstate. _getProdPromo (package:gestoque/products_promotion_Dart:19:5) E/flutter (19914):
I make the Query via Advanced Rest and the following data is returned:
[
{
"ad_codprodint": "40011333ME",
"codprod": 1632,
"descrprod": "BETONEIRA 400L PRIME MONOF 110V MENEGOT",
"vlrvenda": 2850
},
{
"ad_codprodint": "40011333ME",
"codprod": 1632,
"descrprod": "BETONEIRA 400L PRIME MONOF 110V MENEGOT",
"vlrvenda": 3130
},
]
Debug your code and tell us when the error occurs and if possible show some example of the return of your API.
– Matheus Ribeiro
Edit your question with this JSON return, let’s try to get everything organized :D Just click there on the button Edit just above the comments and add the information in your question
– Matheus Ribeiro