Here is the json string that I get by http request. The aim is to display subjects according to the current weekday.
{
"first_name": "First Name",
"batch_name": "Batch 1",
"enrolled_subjects": [
"Subject 4",
"Subject 5"
],
"batch_timetable": {
"Mon": {
"Subject 4": [
"6:00 PM - 7:00 PM"
],
"Subject 5": [
"5:00 PM - 6:00 PM",
"7:00 PM - 8:00 PM"
],
"Subject 6": [
"8:00 PM - 9:00 PM"
]
},
"Tue": {
"Subject 4": [
"6:00 PM - 7:00 PM"
],
"Subject 5": [
"7:00 PM - 8:00 PM"
],
"Subject 6": [
"8:00 PM - 9:00 PM"
]
}, ...so on upto "Sun"
}
}
How to set Model Class for this json string?
I tried this Model Class but it gives this error : type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, List<dynamic>>'
I also tried Model Class by quicktype, but I think that won't work in this case.
class HomePageModel {
HomePageModel({
this.firstName,
this.batchName,
this.subjects,
this.timetable,
});
String firstName;
String batchName;
List<String> subjects;
Map timetable;
factory HomePageModel.fromJson(Map<String, dynamic> json) => HomePageModel(
firstName: json["first_name"],
batchName: json["batch_name"],
subjects: List<String>.from(json["subjects"].map((x) => x)),
timetable: Map.from(json["timetable"])
.map((key, value) => MapEntry(key, value)),
);
Map<String, dynamic> toJson() => {
"first_name": firstName,
"batch_name": batchName,
"subjects": List<dynamic>.from(subjects.map((x) => x)),
"timetable":
Map.from(timetable.map((key, value) => MapEntry(key, value))),
};
}
I am using FutureBuilder to display this data into UI. Any help would be appreciated.