doğan kısa
doğan kısa

Reputation: 43

_TypeError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>') its my error

My api function:

 Future<List<User>>fetchData() async {
var response = await http.get(
    Uri.parse(link),
    headers: headers);
 var jsonData = jsonDecode(response.body);

List<User> users = [];

for (var u in jsonData) {
  User user = User(u["name"], u["code"], u["id"]);
  users.add(user);
}
print(users.length);
return users;

}

im getting this error in for loop. how can i fix it ? i need help. thanks for all

Upvotes: 1

Views: 32

Answers (1)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12353

Your data is probably inside a list inside this json response. Look if you have a "data" field in your response, then your for loop would look something like this:

var u in jsonData["data"]

print our your jsonData and let's see.

Upvotes: 1

Related Questions