Layout changes, fix bugs in new entry page
This commit is contained in:
@@ -83,5 +83,50 @@ extension DataServiceTrips on DataService {
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchTripOptions() async {
|
||||
try {
|
||||
final json = await api.get('/trips');
|
||||
Iterable<dynamic>? raw;
|
||||
if (json is List) {
|
||||
raw = json;
|
||||
} else if (json is Map) {
|
||||
for (final key in ['trips', 'trip_data', 'data']) {
|
||||
final value = json[key];
|
||||
if (value is List) {
|
||||
raw = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (raw != null) {
|
||||
final tripMap = raw
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map((e) => TripSummary.fromJson(e))
|
||||
.toList();
|
||||
|
||||
_tripList = [...tripMap]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
} else {
|
||||
debugPrint('Unexpected trip list response: $json');
|
||||
_tripList = [];
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch trip list: $e');
|
||||
_tripList = [];
|
||||
} finally {
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void upsertTripSummary(TripSummary trip) {
|
||||
final existingIndex =
|
||||
_tripList.indexWhere((element) => element.tripId == trip.tripId);
|
||||
if (existingIndex >= 0) {
|
||||
_tripList[existingIndex] = trip;
|
||||
} else {
|
||||
_tripList = [trip, ..._tripList];
|
||||
}
|
||||
_tripList.sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user