I'm trying to have 2 data responses for 2 api endpoints. 1 is a single response, and the other is an array of a single response.
When trying to create the List/array version, I get errors. What's the proper way to make the following model class into a List as well?
class SingleDataResponse {
final String id;
final String title;
SingleDataResponse({
this.id,
this.title
});
factory SingleDataResponse.fromJson(Map<String, dynamic> json) {
return SingleDataResponse(
id: json['id'],
title: json['title']
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['title'] = this.title;
return data;
}
}
Here's what I'm expecting to get in the List Model:
[{_id: "5f210afa8215ff24307c6c53", title: "Cool Title"}]