i have this json response from an API
{
"success": true,
"routes": [
{
"_id": "613cc90623db8f3418f59f50",
"transit": [
"Addis Ababa",
"Gondar"
],
"startingPlace": {
"country": "Ethiopia",
"city": "Addis Ababa"
},
"destination": {
"country": "Ethiopia",
"city": "Addis Ababa"
},
"distance": 55,
"__v": 0,
"schedule": [
{
"_id": "613e200446560f0508778adf",
"boardingDate": "2020-01-01T00:00:00.000Z",
"arrivalDate": "2020-02-01T00:00:00.000Z",
"driverAssistantId": "612de5d3cf56fc27e8abf629",
"routeId": "613cc90623db8f3418f59f50",
"__v": 0
}
]
}
]
}
i wanted to retrieve the schedule
list inside routes
and this is the function that does the post request.. it returns a list of Schedules
model
Future<List<Schedule>> searchSchedule(SearchScheduleModel model) async {
String token = await getToken();
Map<String, String> headers = {
"Content-Type": "application/json",
'Authorization': 'Bearer $token'
};
final allPlacesURl = Uri.parse("$ipAddress/common/searchBySpAndDes");
var body = searchScheduleModelToJson(model);
var response = await http.post(allPlacesURl, headers: headers, body: body);
if (response.statusCode == 200) {
var body = schedulesModelFromJson(response.body);
List<Route> route = body.routes;
List<Schedule> schedules = [];
//the error is shown here, how can i map a list within alist
schedules = route.map((e) => e.schedule);
return schedules;
}
return json.decode(response.body);
}
but i have this error
A value of type 'Iterable<List<Schedule>>' can't be assigned to a variable of type 'List<Schedule>'.
i dont know how to map it right..