From becf515accd0ad420f9a82c9cd77b7aff2d6d9c4 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 21 Feb 2024 14:34:04 +0300 Subject: [PATCH] feat(diary) Dynamic current meal display --- .../diary_edit_screen/bloc/diary_edit_bloc.dart | 14 +++++++++++--- .../diary_edit_screen/bloc/diary_edit_event.dart | 8 +++----- .../diary/diary_edit_screen/diary_edit_screen.dart | 5 ++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart index 2a912026..3c103e80 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart @@ -40,7 +40,7 @@ class DiaryEditBloc extends Bloc { ) async { try { final token = - "1|laravel_sanctum_8qeVUwDzs440SoG1pJFdSFtYWjJhZfEQXqStVkFPea8d4092"; + "laravel_sanctum_RzcUqh1zBYFCIG5tBFvfxyvA1NER9fMQiKlqlJFYeb618e64"; final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { @@ -61,7 +61,7 @@ class DiaryEditBloc extends Bloc { ); final diary = jsonDecode(response.body)['diary']; if (diary is Map) { - print(diary); + print(diary['meals'][1].runtimeType); final String diaryDate = diary['date'] ?? DateTime.now().toString(); // Продолжайте обработку данных дневника @@ -69,6 +69,7 @@ class DiaryEditBloc extends Bloc { // Если текущее состояние уже загружено, обновляем его var currentState = state as DiaryEditLoadedState; emit((currentState).copyWith( + currentMeal: currentState.currentMeal, wakeupExpanded: currentState.wakeupExpanded, moodExpanded: currentState.moodExpanded, token: currentState.token, @@ -88,6 +89,8 @@ class DiaryEditBloc extends Bloc { } else { // Если текущее состояние - начальное, создаем новое загруженное состояние emit(DiaryEditLoadedState( + currentMeal: SelectionPopupModel( + id: 0, title: "Прием пищи 1", isSelected: true), wakeupExpanded: true, moodExpanded: true, token: token, @@ -229,7 +232,12 @@ class DiaryEditBloc extends Bloc { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - emit(currentState.copyWith(currentMeal: event.value)); + emit(currentState.copyWith( + currentMeal: event.value, + mealTimeController: + toTime(event.meals?[event.value.id ?? 0]['time'] ?? "09:00"), + selectedMood: event.meals?[event.value.id ?? 0]['mood'], + selectedSatiety: event.meals?[event.value.id ?? 0]['satiety'])); currentState.currentMeal = event.value; } } diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart index ab16a29a..8f396765 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart @@ -110,12 +110,10 @@ class UploadImages extends DiaryEditEvent { } class ChangeMeal extends DiaryEditEvent { - ChangeMeal({required this.value}); + ChangeMeal({required this.value, required this.meals}); SelectionPopupModel value; - + List? meals; @override - List get props => [ - value, - ]; + List get props => [value, meals]; } diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 6c33eab4..87d08ed8 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -269,9 +269,8 @@ class DiaryEditScreen extends StatelessWidget { vertical: 9.v, ), onChanged: (value) { - context - .read() - .add(ChangeMeal(value: value)); + context.read().add( + ChangeMeal(meals: state.meals, value: value)); }, ); })),