Suppose I have a json object like this:
{
"sort": "asc",
"page": {
"next": "asdfg",
"prev": "kljekj"
}
}
I wrote a datamodel in dart like this:
class AllPage{
String sort;
Page page;
AllPage({this.sort, this.page});
AllPage.fromJson(Map<String, dynamic> json) {
return AllPage(
sort = json['sort'],
page = Page.fromJson(json['page']));
}
}
class Page {
String next;
String prev;
Page({this.next, this.prev});
Page.fromJson(Map<String, dynamic> json) {
return Page(
next = json['next'],
prev = json['prev']);
}
}
I have seen countless examples in which this works. However, I am getting an error in my AppPage class, inside Page.FromJson(json['page']). The error says: "The argument type 'dynamic' can't be assigned to the parameter type 'Map>string, dynamic>'.
I am new to flutter/dart. So this could be something simple that I am missing. Any help is greatly appreciated. Thank you!