add loco legs panel
Some checks failed
Release / meta (push) Failing after 9s
Release / android-build (push) Has been skipped
Release / linux-build (push) Has been skipped
Release / release-dev (push) Has been skipped
Release / release-master (push) Has been skipped

This commit is contained in:
2025-12-17 14:42:31 +00:00
parent fa9773bcd1
commit e9a9e66e39
7 changed files with 389 additions and 160 deletions

View File

@@ -177,6 +177,38 @@ class DataService extends ChangeNotifier {
);
}
Future<List<Leg>> fetchLegsForLoco(
int locoId, {
bool includeNonPowering = false,
}) async {
if (locoId <= 0) return [];
final params =
includeNonPowering ? '?include_non_powering=true' : '';
try {
final json = await api.get('/legs/$locoId$params');
dynamic list = json;
if (json is Map) {
for (final key in ['legs', 'data', 'results']) {
if (json[key] is List) {
list = json[key];
break;
}
}
}
if (list is List) {
return list
.whereType<Map>()
.map((e) => Leg.fromJson(Map<String, dynamic>.from(e)))
.toList();
}
debugPrint('Unexpected loco legs response: $json');
return [];
} catch (e) {
debugPrint('Failed to fetch loco legs for $locoId: $e');
return [];
}
}
Future<void> fetchHadTraction({int offset = 0, int limit = 100}) async {
await fetchTraction(
hadOnly: true,