I would like to use my JSON file to store all the info in it to display in Flutter.
Everytime i get this Error:
_TypeError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>')
Here are my Files:
db.json
breed_page.dart
Can someone help me solving this error or show me a better way to do this?
Normally, the name and image should be read from the JSON file and then displayed in the list tile as a circle image or as text. I have also checked my JSON file and tried other functions like this one but nothing helped. By the way I am a newbie in Flutter
ListView.builder(
itemCount: breeds.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: Image.network(breeds[index]['img']),
title: Text(breeds[index]['name']),
onTap: () {
// TODO: Navigate to breed details page
},
);
},
);
2
Answers
json.decode(jsonString);
seems to be converting the data fromString
toMap<String, dynamic>
instead ofList<dynamic>
Please go through the language docs to check if you’re using the right return type for your json
https://api.dart.dev/stable/2.19.3/dart-convert/jsonDecode.html
your decoded json string is
Map<String,dynamic>
not aList<dynamic>
the
List
are a value from keybreeds
Workaroud: