fix navbar freezing fix
This commit is contained in:
@@ -209,22 +209,46 @@ class DataService extends ChangeNotifier {
|
||||
final target = date ?? DateTime.now();
|
||||
final formatted =
|
||||
"${target.year.toString().padLeft(4, '0')}-${target.month.toString().padLeft(2, '0')}-${target.day.toString().padLeft(2, '0')}";
|
||||
final endpoint = '/legs/on-this-day?date=$formatted';
|
||||
dynamic json;
|
||||
Object? lastError;
|
||||
for (int attempt = 0; attempt < 2; attempt++) {
|
||||
try {
|
||||
json = await api.get(endpoint);
|
||||
lastError = null;
|
||||
break;
|
||||
} catch (e) {
|
||||
lastError = e;
|
||||
if (!_looksLikeOnThisDayRoutingConflict(e)) break;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final json = await api.get('/legs/on-this-day?date=$formatted');
|
||||
if (json is List) {
|
||||
_onThisDay = json.map((e) => Leg.fromJson(e)).toList();
|
||||
} else {
|
||||
_onThisDay = [];
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch on-this-day legs: $e');
|
||||
lastError ??= e;
|
||||
_onThisDay = [];
|
||||
} finally {
|
||||
if (lastError != null) {
|
||||
debugPrint('Failed to fetch on-this-day legs ($endpoint): $lastError');
|
||||
}
|
||||
_isOnThisDayLoading = false;
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
bool _looksLikeOnThisDayRoutingConflict(Object error) {
|
||||
final msg = error.toString();
|
||||
return msg.contains('API error 422') &&
|
||||
msg.contains('[path, loco_id]') &&
|
||||
msg.contains('input: on-this-day');
|
||||
}
|
||||
|
||||
Future<void> fetchEventFields({bool force = false}) async {
|
||||
if (_eventFields.isNotEmpty && !force) return;
|
||||
_isEventFieldsLoading = true;
|
||||
|
||||
Reference in New Issue
Block a user