Public Access
fix(transport_helper): add color parsing for line
This commit is contained in:
@@ -782,10 +782,10 @@ class Line {
|
||||
"lineid": lineId,
|
||||
"destination": destination,
|
||||
"direction": direction,
|
||||
"mode": mode,
|
||||
"mode": mode.toString(),
|
||||
"name": name,
|
||||
"fgcolor": fgColor,
|
||||
"bgcolor": bgColor,
|
||||
"fgcolor": fgColor.toString(),
|
||||
"bgcolor": bgColor.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -794,7 +794,12 @@ class Line {
|
||||
lineId: map["lineId"] as String,
|
||||
destination: map["destination"] as String,
|
||||
direction: map["direction"] as String,
|
||||
mode: map["mode"] as VehicleType,
|
||||
// Source - https://stackoverflow.com/a/44060511
|
||||
// Posted by Collin Jackson, modified by community. See post 'Timeline' for change history
|
||||
// Retrieved 2026-07-29, License - CC BY-SA 4.k
|
||||
mode: VehicleType.values.firstWhere(
|
||||
(e) => e.toString() == 'VehicleType.${map["mode"] as String}',
|
||||
),
|
||||
name: map["name"] as String,
|
||||
fgColor: map["fgcolor"] as Color,
|
||||
bgColor: map["bgcolor"] as Color,
|
||||
@@ -1092,11 +1097,28 @@ class Color {
|
||||
required this.b,
|
||||
});
|
||||
|
||||
factory Color.fromStringRGBComma(String input) {
|
||||
List<String> split = input.split(",");
|
||||
if (split.length == 3) {
|
||||
return Color(
|
||||
r: int.parse(split[0]),
|
||||
g: int.parse(split[1]),
|
||||
b: int.parse(split[2]),
|
||||
);
|
||||
}
|
||||
return Color(r: 128, g: 128, b: 128);
|
||||
}
|
||||
|
||||
factory Color.fromJson(Map<String, dynamic> json) => Color(
|
||||
r: json["r"],
|
||||
g: json["g"],
|
||||
b: json["b"],
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$r,$g,$b';
|
||||
}
|
||||
}
|
||||
|
||||
enum VehicleType {
|
||||
@@ -1106,4 +1128,4 @@ enum VehicleType {
|
||||
subway,
|
||||
regionalTrain,
|
||||
PLACEHOLDER,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user