Home > Net >  Flutter : can't get all response body from get request
Flutter : can't get all response body from get request

Time:02-28

I have get request in Flutter app, when I test the request in postman I get all data, something like this :

{
"result":{
   "name" : "somename",
   "images":[
      "test.jpg",
      "test2.jpg"
    ],
   "sizes":[
     {
       "id": 1,
       "value" : 5
     },
     {
       "id": 2,
       "value" : 15
     }
    ]
 }
}

I call data and print them like this without using models:

var data = json.decode(response.body);
print(data['result']['name']);
print(data['result']['images']);
print(data['result']['sizes']);

it is print all things expect last one.

where must be the mistake?

CodePudding user response:

Solved, by adding "?sizesView = true" to the link

final response = await http.get(path  '?sizesView = true'):

CodePudding user response:

you should get the index of the last one because it is in a dictionary not a list do this:

print(data['result']['sizes'][0]['id']) // it will get the first index of the sizes list and then get the id key 

or you can creat a model of list to get the indexes of your list

  • Related