add loco legs panel
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user