feat(UI): add screens for choosing stations and vehicles (WIP)

This commit is contained in:
fbachus
2026-07-21 03:13:35 +02:00
parent 3850cea0e8
commit d7aa2a1b46
2 changed files with 264 additions and 73 deletions
+50 -21
View File
@@ -438,7 +438,7 @@ class Station {
});
Map<String, Object?> _toMap() {
return {"id": id, "name": name};
return {"stationid": id, "name": name};
}
List<Map<String, Object?>> _toMapLines() {
@@ -455,20 +455,26 @@ class Station {
List<Line>? stationLines,
}) {
return Station(
id: map["id"] as String,
id: map["stationid"] as String,
name: map["name"] as String,
transportLines: stationLines ?? List.empty(),
);
}
factory Station.fromJson(Map<String, dynamic> json) => Station(
id: json["id"] ?? json["extId"] as String,
name: json["name"],
transportLines: json.containsKey("productAtStop")
? json["productAtStop"].map(
(jsonLine) => Line.fromJson(jsonLine as Map<String, dynamic>),
)
: const [],
id: json["id"] as String,
name: json["name"] as String,
transportLines:
json.containsKey("productAtStop") && json["productAtStop"] != Null
? json["productAtStop"]
.map(
(jsonLine) => //jsonLine != Null
/*?*/ Line.fromJson(jsonLine! as Map<String, dynamic>),
//: Null,
)
.toList()
.cast<Line>()
: [],
);
static void initStationTable() async {
@@ -563,16 +569,19 @@ class Vehicle {
static const String tableName = "vehicle";
String id;
String name;
String vehicleLineId;
Vehicle({
required this.id,
required this.name,
required this.vehicleLineId,
});
Map<String, Object?> _toMap() {
return {
"id": id,
"name": name,
"line": vehicleLineId,
};
}
@@ -582,6 +591,7 @@ class Vehicle {
) {
return Vehicle(
id: map["id"] as String,
name: map["name"] as String,
vehicleLineId: map["line"] as String,
);
}
@@ -589,7 +599,8 @@ class Vehicle {
// 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"],
id: json["num"],
name: json["name"],
vehicleLineId: Line.fromJson(json).lineId,
);
@@ -597,7 +608,8 @@ class Vehicle {
Database database = DbHelper.db;
String line = Line.tableName;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName(
id TEXT PRIMARY KEY,
id TEXT PRIMARY KEY,
name TEXT,
line TEXT,
FOREIGN KEY(line) REFERENCES $line(lineid)
);
@@ -684,14 +696,14 @@ class Line {
];
factory Line.fromJson(Map<String, dynamic> json) => Line(
lineId: json["lineId"],
name: json["name"],
mode: _vehicleTypeAsCatCode[int.parse(json["catCode"])],
lineId: json["lineId"] as String,
name: json["name"] as String,
mode: _vehicleTypeAsCatCode[int.parse(json["catCode"] as String)],
fgColor:
Color.fromJson(json["foregroundColor"]) as Color? ??
Color.fromJson(json["icon"]["foregroundColor"]) as Color? ??
Color(r: 255, g: 255, b: 255), // fallback
bgColor:
Color.fromJson(json["backgroundColor"]) as Color? ??
Color.fromJson(json["icon"]["backgroundColor"]) as Color? ??
Color(r: 50, g: 50, b: 50), // fallback
);
static void initLineTable() async {
@@ -744,12 +756,14 @@ class Departure {
int? id;
String vehicleId;
String vehicleName;
String stationId;
DateTime departureTime;
Departure({
this.id,
required this.vehicleId,
required this.vehicleName,
required this.stationId,
required this.departureTime,
});
@@ -758,6 +772,7 @@ class Departure {
return {
"id": id,
"vehicle": vehicleId,
"vehiclename": vehicleName,
"station": stationId,
"departuretime": departureTime,
};
@@ -767,19 +782,33 @@ class Departure {
return Departure(
id: map["id"] as int,
vehicleId: map["vehicle"] as String,
vehicleName: map["vehiclename"] as String,
stationId: map["station"] as String,
departureTime: map["departuretime"] as DateTime,
);
}
factory Departure.fromJson(Map<String, dynamic> json) {
Vehicle vehicle = Vehicle.fromJson(json["Product"]);
vehicle.dbInsert();
Station station = Station.fromJson(json["stop"]);
station.dbInsert();
Vehicle vehicle = Vehicle.fromJson(json["Product"][0]);
// try {
// vehicle.dbInsert();
// } catch (e) {
// vehicle.dbUpdate();
// }
Station station = Station(
id: json["stopid"],
name: json["stop"],
transportLines: [],
);
// try {
// station.dbInsert();
// } catch (e) {
// station.dbUpdate();
// }
return Departure(
vehicleId: vehicle.id,
vehicleName: vehicle.name,
stationId: station.id,
departureTime: json["time"],
departureTime: DateTime.parse('${json["date"]}T${json["time"]}'),
);
}