0
Hello, I am trying to recover the json data from a URL, I am following this tutorial
https://inducesmile.com/google-flutter/how-to-populate-dropdownbutton-using-json-api-in-flutter/ I was able to reproduce successfully.
But with my Json url I’m in trouble. Json is a little different;
Tutorial Json Format
[{"id": 1, "name": "Leanne Graham"},{"id": 2,"name": "Ervin Howell"}]
Json format my URL
{"data":[{ "id":1, "name":"Acre" }, { "id":2, "name":"Alagoas" }]}
This is the part where I’m in trouble
final items = json.decode(response.body).cast<Map<String, dynamic>>();
As following error:
NoSuchMethodError (NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments.
No need to cast, return json.Decode() is already a Map.
– Julio Henrique Bitencourt