Layout changes, fix bugs in new entry page
This commit is contained in:
@@ -114,5 +114,40 @@ extension DataServiceTraction on DataService {
|
||||
}
|
||||
return _locoClasses;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchLatestLocoChanges({int limit = 25, int offset = 0}) async {
|
||||
_isLatestLocoChangesLoading = true;
|
||||
_notifyAsync();
|
||||
try {
|
||||
final json =
|
||||
await api.get('/loco/changes/latest?limit=$limit&offset=$offset');
|
||||
dynamic results = json;
|
||||
if (json is Map && json['data'] is List) {
|
||||
results = json['data'];
|
||||
}
|
||||
if (results is List) {
|
||||
final parsed = <LocoChange>[];
|
||||
for (final item in results) {
|
||||
if (item is Map<String, dynamic>) {
|
||||
parsed.add(LocoChange.fromJson(item));
|
||||
} else if (item is Map) {
|
||||
parsed.add(
|
||||
LocoChange.fromJson(
|
||||
item.map((key, value) => MapEntry(key.toString(), value)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
_latestLocoChanges = parsed;
|
||||
} else {
|
||||
throw Exception('Unexpected latest loco changes response: $json');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch latest loco changes: $e');
|
||||
_latestLocoChanges = [];
|
||||
} finally {
|
||||
_isLatestLocoChangesLoading = false;
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user