fix(diary): some fixes offline-diary

This commit is contained in:
mso7nueh
2026-05-14 19:52:15 +03:00
parent 63fc824449
commit af3b40d5f2
11 changed files with 114 additions and 228 deletions

View File

@@ -156,7 +156,14 @@ class DiaryCubit extends Cubit<DiaryState> {
}
} catch (e, st) {
await reportFrom(e, st, this);
log(e.toString());
log('updateCurrentDiary error: $e');
// BUG-1 fix: офлайн fallback — перезагружаем из кэша, чтобы UI
// отразил изменения, выполненные пользователем.
try {
await fetchDiaryV2(needLoading: false, diaryId: diaryId);
} catch (_) {
// Не критично — UI останется на текущем состоянии
}
}
}
@@ -351,8 +358,9 @@ class DiaryCubit extends Cubit<DiaryState> {
planDuration = chosenPlanModel.plan.duration;
planName = chosenPlanModel.plan.name;
currentPlanDay = consultantReview.currentPlanDay;
} catch (_) {
// Офлайн — данные плана недоступны
} catch (e) {
// BUG-9 fix: офлайн — данные плана недоступны, логируем для отладки
log('[setDiary] Plan/comments data unavailable (offline?): $e');
}
}
@@ -431,7 +439,11 @@ class DiaryCubit extends Cubit<DiaryState> {
required int quantity,
int? productNutritionalValueId,
}) async {
emit((state as DiaryStateLoaded).copyWith(isLoadingAddingProductInMeal: true));
// BUG-2 fix: безопасная проверка типа стейта перед кастом
final currentState = state;
if (currentState is DiaryStateLoaded) {
emit(currentState.copyWith(isLoadingAddingProductInMeal: true));
}
try {
await diaryRepository.addPortionToMeal(
diaryId: diaryId,