forked from eatvio/eatvio_app
feat(diary): improve stability
This commit is contained in:
@@ -45,6 +45,8 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
|
||||
// Подписка на изменения connectivity
|
||||
StreamSubscription<InternetConnectionState>? _connectivitySubscription;
|
||||
// Подписка на принудительное обновление дневника
|
||||
StreamSubscription<String>? _forceFetchSubscription;
|
||||
|
||||
DiaryCubit({
|
||||
required this.chatRepository,
|
||||
@@ -58,7 +60,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
}) : super(const DiaryState.loading()) {
|
||||
today = DateTime.now();
|
||||
selectedDay = today;
|
||||
diaryRepository.forceFetchStream.listen((_) {
|
||||
_forceFetchSubscription = diaryRepository.forceFetchStream.listen((_) {
|
||||
fetchDiaryV2(needLoading: true, diaryId: diaryId);
|
||||
});
|
||||
// При переходе offline→online перезагружаем дневник
|
||||
@@ -117,7 +119,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
: 'Нет интернета. Откройте дневник онлайн хотя бы один раз, чтобы он был доступен офлайн.';
|
||||
log('[fetchDiaryV2] diaryDay is null, msg=$msg');
|
||||
emit(DiaryState.error(errorMessage: msg));
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
log('[fetchDiaryV2] diaryDay loaded, id=${diaryDay.id}, converting to entity...');
|
||||
@@ -609,6 +611,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
@override
|
||||
Future<void> close() {
|
||||
_connectivitySubscription?.cancel();
|
||||
_forceFetchSubscription?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user