Public Access
feat(json import): add fromJson to missing classes and connect them
This commit is contained in:
@@ -1,3 +1,46 @@
|
||||
class Route {
|
||||
List<Segment> segments = List.empty();
|
||||
Duration duration = Duration(minutes: 0);
|
||||
|
||||
Route({
|
||||
required this.segments,
|
||||
required this.duration,
|
||||
});
|
||||
|
||||
// from trip API request
|
||||
|
||||
factory Route.fromJson(Map<String, dynamic> json) => Route(
|
||||
segments: json["Leglist"]["Leg"].map((leg) => Segment.fromJson(leg)),
|
||||
duration: json["LegList"]["Leg"][-1]["Origin"]["time"] -
|
||||
json["LegList"]["Leg"][0]["Origin"]["time"],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
class Segment {
|
||||
final Station startPoint;
|
||||
final Station endPoint;
|
||||
final DateTime startTime;
|
||||
final DateTime endTime;
|
||||
final Vehicle vehicle;
|
||||
|
||||
Segment({
|
||||
required this.startPoint,
|
||||
required this.endPoint,
|
||||
required this.startTime,
|
||||
required this.endTime,
|
||||
required this.vehicle,
|
||||
});
|
||||
|
||||
factory Segment.fromJson(Map<String, dynamic> json) => Segment(
|
||||
startPoint: Station.fromJson(json["Origin"]),
|
||||
endPoint: Station.fromJson(json["Destination"]),
|
||||
startTime: json["Origin"]["rtTime"],
|
||||
endTime: json["Destination"]["rtTime"],
|
||||
vehicle: Vehicle.fromJson(json["Product"]),
|
||||
);
|
||||
}
|
||||
|
||||
class Station {
|
||||
final String id;
|
||||
final String name;
|
||||
@@ -22,16 +65,19 @@ class Station {
|
||||
|
||||
class Vehicle {
|
||||
final String id;
|
||||
final String name;
|
||||
final List<Departure>? departures;
|
||||
final Line line;
|
||||
|
||||
Vehicle({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.departures
|
||||
required this.line,
|
||||
});
|
||||
|
||||
factory Vehicle.fromJson(Map<String, dynamic> json)
|
||||
// we can use the "product" class from within any JSON response
|
||||
// (within hafas API, on the appropriate level)
|
||||
factory Vehicle.fromJson(Map<String, dynamic> json) => Vehicle(
|
||||
id: json["matchId"],
|
||||
line: Line.fromJson(json),
|
||||
);
|
||||
}
|
||||
|
||||
class Line {
|
||||
@@ -51,6 +97,7 @@ class Line {
|
||||
this.bgColor,
|
||||
});
|
||||
|
||||
// TODO: EXPLAIN!!!!!!!!!!!!
|
||||
static const _vehicleTypeAsCatCode = [
|
||||
VehicleType.metro,
|
||||
VehicleType.subway,
|
||||
|
||||
Reference in New Issue
Block a user