diff --git a/lib/transport_helper.dart b/lib/transport_helper.dart new file mode 100644 index 0000000..b87ff18 --- /dev/null +++ b/lib/transport_helper.dart @@ -0,0 +1,111 @@ +class Station { + final String id; + final String name; + List? transportLines; + List? departures; + + Station({ + required this.id, + required this.name, + required this.transportLines + }); + + factory Station.fromJson(Map 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)) + : const [], + ); +} + +class Vehicle { + final String id; + final String name; + final List? departures; + + Vehicle({ + required this.id, + required this.name, + required this.departures + }); + + factory Vehicle.fromJson(Map 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 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 json) => Color( + r: json["r"], + g: json["g"], + b: json["b"] + ); +} + + +enum VehicleType{ + bus, + tram, + metro, + subway, + regionalTrain, + PLACEHOLDER +}