Public Access
fix(transport_helper): add color parsing for line
This commit is contained in:
@@ -782,10 +782,10 @@ class Line {
|
|||||||
"lineid": lineId,
|
"lineid": lineId,
|
||||||
"destination": destination,
|
"destination": destination,
|
||||||
"direction": direction,
|
"direction": direction,
|
||||||
"mode": mode,
|
"mode": mode.toString(),
|
||||||
"name": name,
|
"name": name,
|
||||||
"fgcolor": fgColor,
|
"fgcolor": fgColor.toString(),
|
||||||
"bgcolor": bgColor,
|
"bgcolor": bgColor.toString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -794,7 +794,12 @@ class Line {
|
|||||||
lineId: map["lineId"] as String,
|
lineId: map["lineId"] as String,
|
||||||
destination: map["destination"] as String,
|
destination: map["destination"] as String,
|
||||||
direction: map["direction"] 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,
|
name: map["name"] as String,
|
||||||
fgColor: map["fgcolor"] as Color,
|
fgColor: map["fgcolor"] as Color,
|
||||||
bgColor: map["bgcolor"] as Color,
|
bgColor: map["bgcolor"] as Color,
|
||||||
@@ -1092,11 +1097,28 @@ class Color {
|
|||||||
required this.b,
|
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(
|
factory Color.fromJson(Map<String, dynamic> json) => Color(
|
||||||
r: json["r"],
|
r: json["r"],
|
||||||
g: json["g"],
|
g: json["g"],
|
||||||
b: json["b"],
|
b: json["b"],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return '$r,$g,$b';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VehicleType {
|
enum VehicleType {
|
||||||
|
|||||||
Reference in New Issue
Block a user