Flutter Complex Map and List

hello ,
i have this data come from api

data{
“keyOne”: [
{“id”:1,“name”:‘moahmed’},
{“id”:2,“name”:‘ahmed’},
{“id”:3,“name”:‘mostafa’},],
“keyTwp”: [{“id”:1,“name”:‘tree’},
{“id”:2,“name”:‘flower’},
{“id”:3,“name”:‘see’},
]
}

how to implement the model for this

1 Like

Request you try some methods by yourself, if you are facing any issue, please do post here. :slight_smile:

class Credits {
List cast;
List crew;
Credits({this.cast, this.crew});
factory Credits.fromJson(Map<String, List<Map<String, dynamic>>> jsonObject){
List<Map<String, dynamic>> casts = jsonObject[‘cast’];
List<Map<String, dynamic>> crew = jsonObject[‘crew’];
return Credits(
cast: casts.map((Map<String, dynamic> f) => Cast.fromJson(f)).toList(),
crew: crew.map((Map<String, dynamic> f) => Crew.fromJson(f)).toList(),
);
}
}
class Cast {
int cast_id;
String character;
String credit_id;
int gender;
int id;
String name;
int order;
String profile_path;
Cast(
{this.profile_path, this.credit_id, this.gender, this.name, this.id, this.cast_id, this.character, this.order});
factory Cast.fromJson(Map<String, dynamic> jsonObject){
return Cast(
profile_path: jsonObject[‘profile_path’],
gender: jsonObject[‘gender’],
id: jsonObject[‘id’],
name: jsonObject[‘name’],
cast_id: jsonObject[‘cast_id’],
character: jsonObject[‘character’],
credit_id: jsonObject[‘credit_id’],
order: jsonObject[‘order’],
);
}
}
class Crew{
String credit_id;
String department;
String gender;
int id;
String job;
String name;
String profile_path;
Crew({this.id,this.name,this.gender,this.credit_id,this.department,this.job,this.profile_path});
factory Crew.fromJson(Map<String ,dynamic> jsonObject){
return Crew(
name: jsonObject[‘name’],
id: jsonObject[‘id’],
gender: jsonObject[‘gender’],
credit_id: jsonObject[‘credit_id’],
department: jsonObject[‘department’],
job: jsonObject[‘job’],
profile_path: jsonObject[‘profile_path’],
);
}
}
i get this error AsyncSnapshot(ConnectionState.done, null, type ‘_InternalLinkedHashMap<String, dynamic>’ is not a subtype of type ‘Credits’).data