diff --git a/lib/api_handler.dart b/lib/api_handler.dart index 2851627..0f19c6a 100644 --- a/lib/api_handler.dart +++ b/lib/api_handler.dart @@ -67,9 +67,12 @@ class ApiHandler { ); final httpPackageJson = json.decode(jsonResponse.body) as Map; - final stationList = httpPackageJson["stopLocationOrCoordLocation"].map( - (x) => Station.fromJson(x["StopLocation"]), - ); + final stationList = httpPackageJson["stopLocationOrCoordLocation"] + .map( + (x) => Station.fromJson(x["StopLocation"]), + ) + .toList() + .cast(); return stationList; } @@ -139,13 +142,16 @@ class ApiHandler { ); final httpPackageJson = json.decode(jsonResponse.body) as Map; - List departureList = httpPackageJson["Departure"].map( - (x) => Departure.fromJson(x), - ); + List departureList = httpPackageJson["Departure"] + .map( + (x) => Departure.fromJson(x), + ) + .toList() + .cast(); return departureList; } - static Future> trip( + static Future> trip( String originId, String destinationId, { String? via, @@ -179,13 +185,17 @@ class ApiHandler { ); final httpPackageJson = json.decode(jsonResponse.body) as Map; - final idList = httpPackageJson["Trip"].map( - (x) => x["LegList"]["Leg"].map((y) => y["JourneyDetail"]["ref"]), - ); - return idList; + // TODO: here lurk problems - do we get a list of list of segments? can't cast it– + // what do we want from this? + List SegmentList = httpPackageJson["Trip"] + .map( + (x) => x["LegList"]["Leg"].map((y) => Segment.fromJson(y)), + ) + .toList(); + return SegmentList; } - static Future> tripDetail( + static Future> tripDetail( String id, { String? date, String? fromId, @@ -206,7 +216,12 @@ class ApiHandler { ); final httpPackageJson = json.decode(jsonResponse.body) as Map; - final idList = httpPackageJson["Stops"]["Stop"].map((x) => x["id"]); - return idList; + final DepartureList = httpPackageJson["Stops"]["Stop"] + .map( + (x) => Departure.fromJson(x), + ) + .toList() + .cast(); + return DepartureList; } -} +} \ No newline at end of file