feat(diary):

This commit is contained in:
mso7nueh
2024-11-11 04:57:41 +03:00
parent e3fc4811b8
commit 9b7e972268
5 changed files with 264 additions and 190 deletions

View File

@@ -10,6 +10,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
class DiaryCubit extends Cubit<DiaryState> {
final DiaryRepository diaryRepository;
final GlossaryRepository glossaryRepository;
double currentSelectedSatietyRating = 3;
DiaryCubit({
required this.diaryRepository,
@@ -19,7 +20,12 @@ class DiaryCubit extends Cubit<DiaryState> {
getDiaryDay(String date, [bool needLoading = true]) async {
if (needLoading) emit(const DiaryState.loading());
try {
emit(DiaryState.loaded(diary: await diaryRepository.getDiaryByDate(date)));
emit(
DiaryState.loaded(
diary: await diaryRepository.getDiaryByDate(date),
currentSelectedSatietyRating: currentSelectedSatietyRating,
),
);
} catch (e) {
emit(DiaryState.error(errorMessage: e.toString()));
throw e;
@@ -109,4 +115,9 @@ class DiaryCubit extends Cubit<DiaryState> {
);
await getDiaryDay(date, false);
}
updateCurrentSelectedSatietyRating(double value) {
currentSelectedSatietyRating = value;
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: currentSelectedSatietyRating));
}
}