I am trying to parse data from a json. I think this image will help you to understand the problem.
I am getting
Exception has occurred.
_TypeError (type '(dynamic) => MainRank' is not a subtype of type '(String, dynamic) => MapEntry<dynamic, dynamic>' of 'transform')
If you hover over the body, you will see the black pop up with the data. ranks is a list and there are two extra properties there as well.
My MainRank class is like this
class MainRank{
String divisionName;
String tournamentName;
final List<Ranks> ranks;
MainRank(this.divisionName, this.tournamentName, this.ranks);
factory MainRank.fromJson(Map<String, dynamic> json) =>
_$MainRankFromJson(json);
Map<String, dynamic> toJson() => _$MainRankToJson(this);
}
Please help me with a little bit explanation how it works in dart. I am from php/js background so data types seems giving me hard time :) Thank you,
EDIT Response from my api is
{
ranks: [....],
divisionName: "Division 2",
tournamentName: "Season 4"
}
And code I am using to parse the json is
Future _getData() async{
var res = await CallApi().getData('standings/${widget.id}');
final body = json.decode(res.body);
// final matches = body['matches'];
var data;
if(body!=null){
data = body.map((el) => MainRank.fromJson(el));
}
print(data);
return null;
}

data = body.map((el) => MainRank.fromJson(el));