Error while parsing JSON flutter
I/flutter ( 6858): type 'MappedListIterable<dynamic, dynamic>' is not a subtype of type 'List<SearchModel>'
Where am I doing wrong? How could I parse exact file /line-location of error?
{
"total": 24,
"totalPages": 1,
"currentPage": 1,
"perPageRecords": 50,
"values": [
{
"_id": "563e2cce31821525104dfe0c",
"name": "dard ho dil mein to dawaa kiji",
"deleted": false
},
{
"_id": "563e2cce31821525104dfe0b",
"name": "mulk-e-adam main yaaruun ky Id ho rahi hai",
"description": "",
"deleted": false
}
]
Sample Model crearted this way
class SearchPagination {
int total;
int totalPages;
String currentPage;
int perPageRecords;
List<SearchModel> values;
SearchPagination({this.total, this.totalPages, this.currentPage, this.perPageRecords, this.values});
factory SearchPagination.fromJson(Map<String, dynamic> json) {
return SearchPagination(
total: json["total"] as int,
totalPages: json["totalPages"] as int,
currentPage: json["currentPage"] as int,
perPageRecords: json["perPageRecords"] as int,
values: json["values"].map((a) => SearchModel.fromJson(a)),
);
}
}
class SearchModel {
final String id;
final String name;
final String description;
final bool deleted;
SearchModel({this.id, this.name, this.description, this.deleted});
factory SearchModel.fromJson(Map<SearchModel, dynamic> json) {
return SearchModel(id: json["id"], name: json["name"], description: json["description"] as String, deleted: json["deleted"]);
}
}
This way service is being called
Future<SearchPagination> fetchSearches({int page: 1}) async {
var url = Uri.https(baseFinalUrl, 'additional/searches', {'page': page.toString()});
return _getJson(url).then((json) {
print(json);
return SearchPagination.fromJson(json);
});
}
What is exact error while parsing JSON? Is there any line to line debugger for a flutter?