Here I'm trying to make a future listview builder, getting an error message: _TypeError (type 'List' is not a subtype of type 'Map') flutter. I need to get all data inside the post in the list view . Created model class using JSON to dart converter quicktype.io
Future Call
Future<Posts> getPosts() async {
try {
final response =
await http.get(Uri.https('jsonplaceholder.typicode.com', 'posts'));
var data = jsonDecode(response.body);
return Posts.fromJson(data);
} catch (e) {
print(e);
}
}
Model
List<Posts> postsFromJson(String str) => List<Posts>.from(json.decode(str).map((x) => Posts.fromJson(x)));
String postsToJson(List<Posts> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Posts {
Posts({
this.userId,
this.id,
this.title,
this.body,
});
int userId;
int id;
String title;
String body;
factory Posts.fromJson(Map<String, dynamic> json) => Posts(
userId: json["userId"],
id: json["id"],
title: json["title"],
body: json["body"],
);
Map<String, dynamic> toJson() => {
"userId": userId,
"id": id,
"title": title,
"body": body,
};
}