Public Access
feat(data_mapping): add constructors for most publictransport classes
This commit is contained in:
@@ -0,0 +1,111 @@
|
|||||||
|
class Station {
|
||||||
|
final String id;
|
||||||
|
final String name;
|
||||||
|
List<Line>? transportLines;
|
||||||
|
List<Departure>? departures;
|
||||||
|
|
||||||
|
Station({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.transportLines
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Station.fromJson(Map<String, dynamic> json) => Station(
|
||||||
|
id: json["id"] as String? ?? json["extId"] as String,
|
||||||
|
name: json["name"],
|
||||||
|
transportLines: json.containsKey("productAtStop")
|
||||||
|
? json["productAtStop"].map((jsonLine) =>
|
||||||
|
Line.fromJson(jsonLine as Map<String, dynamic>))
|
||||||
|
: const [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Vehicle {
|
||||||
|
final String id;
|
||||||
|
final String name;
|
||||||
|
final List<Departure>? departures;
|
||||||
|
|
||||||
|
Vehicle({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.departures
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Vehicle.fromJson(Map<String, dynamic> json)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Line {
|
||||||
|
final String id;
|
||||||
|
Station? destination;
|
||||||
|
Station? direction;
|
||||||
|
final VehicleType mode;
|
||||||
|
final String name;
|
||||||
|
Color? fgColor;
|
||||||
|
Color? bgColor;
|
||||||
|
|
||||||
|
Line({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.mode,
|
||||||
|
this.fgColor,
|
||||||
|
this.bgColor,
|
||||||
|
});
|
||||||
|
|
||||||
|
static const _vehicleTypeAsCatCode = [
|
||||||
|
VehicleType.metro,
|
||||||
|
VehicleType.subway,
|
||||||
|
VehicleType.PLACEHOLDER,
|
||||||
|
VehicleType.bus
|
||||||
|
];
|
||||||
|
|
||||||
|
factory Line.fromJson(Map<String, dynamic> json) => Line(
|
||||||
|
id: json["lineId"],
|
||||||
|
name: json["name"],
|
||||||
|
mode: _vehicleTypeAsCatCode[int.parse(json["catCode"])],
|
||||||
|
fgColor: Color.fromJson(json["foregroundColor"]) as Color?
|
||||||
|
?? Color(r: 255, g: 255, b: 255), // fallback
|
||||||
|
bgColor: Color.fromJson(json["backgroundColor"]) as Color?
|
||||||
|
?? Color(r: 50, g: 50, b: 50), // fallback
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Departure {
|
||||||
|
String? id;
|
||||||
|
final Vehicle vehicle;
|
||||||
|
final Station station;
|
||||||
|
final DateTime departureTime;
|
||||||
|
|
||||||
|
Departure({
|
||||||
|
required this.vehicle,
|
||||||
|
required this.station,
|
||||||
|
required this.departureTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class Color {
|
||||||
|
final int r;
|
||||||
|
final int g;
|
||||||
|
final int b;
|
||||||
|
|
||||||
|
Color({
|
||||||
|
required this.r,
|
||||||
|
required this.g,
|
||||||
|
required this.b
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Color.fromJson(Map<String, dynamic> json) => Color(
|
||||||
|
r: json["r"],
|
||||||
|
g: json["g"],
|
||||||
|
b: json["b"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum VehicleType{
|
||||||
|
bus,
|
||||||
|
tram,
|
||||||
|
metro,
|
||||||
|
subway,
|
||||||
|
regionalTrain,
|
||||||
|
PLACEHOLDER
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user