From 5681a8df1c8dd45ee9e9069a8229962c4d7a0eff Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 20 Mar 2024 14:31:21 +0300 Subject: [PATCH] feat(diary): New state variable for moderation button control --- .../diary_edit_screen/bloc/diary_edit_bloc.dart | 14 +++++++------- .../diary_edit_screen/bloc/diary_edit_state.dart | 5 +++++ test/diary_test.dart | 1 + 3 files changed, 13 insertions(+), 7 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 32a1c63..ae978ad 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 @@ -74,6 +74,7 @@ class DiaryEditBloc extends Bloc { currentMeal: currentState.currentMeal, wakeupExpanded: currentState.wakeupExpanded, moodExpanded: currentState.moodExpanded, + moderationExpanded: currentState.moderationExpanded, token: currentState.token, meals: currentState.meals, wakeupController: currentState.wakeupController, @@ -97,6 +98,7 @@ class DiaryEditBloc extends Bloc { id: 1, title: "Прием пищи 1", isSelected: true), wakeupExpanded: true, moodExpanded: true, + moderationExpanded: false, token: token, meals: diary['meals'], portions: diary['meals'][0]['portions'], @@ -267,7 +269,6 @@ class DiaryEditBloc extends Bloc { body: json.encode(credentials), encoding: utf8, ); - print(response.body); return response; } @@ -464,9 +465,12 @@ class DiaryEditBloc extends Bloc { .toList(), ); + if (event.input.length > 3) { + updatedState = updatedState.copyWith( + moderationExpanded: !currentState.moderationExpanded); + } + emit(updatedState); // Emit the updated state - } else { - print("Ошибка в декодировании ответа из API"); } } } @@ -494,7 +498,6 @@ class DiaryEditBloc extends Bloc { final updatedState = currentState.copyWith(portions: updatedPortions); emit(updatedState); // Emit the updated state - print("removed"); } } } @@ -513,13 +516,10 @@ class DiaryEditBloc extends Bloc { encoding: utf8, ); - print(response.body); return response; } Future _finishDay(FinishDay event, Emitter emit) async { - print("imageUrl"); - if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index c518e9a..e3dd402 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -35,6 +35,7 @@ class DiaryEditLoadedState extends DiaryEditState { this.currentMeal, required this.diaryId, required this.selectedSatiety, + required this.moderationExpanded, required this.wakeupExpanded, required this.moodExpanded}) : super(diaryEditModelObj: null); @@ -56,6 +57,7 @@ class DiaryEditLoadedState extends DiaryEditState { int selectedSatiety; int diaryId; bool wakeupExpanded; + bool moderationExpanded; bool moodExpanded; @override List get props => [ @@ -75,6 +77,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryId, wakeupExpanded, moodExpanded, + moderationExpanded, currentMeal ]; DiaryEditLoadedState copyWith({ @@ -95,6 +98,7 @@ class DiaryEditLoadedState extends DiaryEditState { int? selectedSatiety, int? diaryId, bool? wakeupExpanded, + bool? moderationExpanded, bool? moodExpanded, }) { return DiaryEditLoadedState( @@ -117,6 +121,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryId: diaryId ?? this.diaryId, currentMeal: currentMeal ?? this.currentMeal, wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded, + moderationExpanded: moderationExpanded ?? this.moderationExpanded, moodExpanded: moodExpanded ?? this.moodExpanded); } } diff --git a/test/diary_test.dart b/test/diary_test.dart index 7d5b9d3..8db84f6 100644 --- a/test/diary_test.dart +++ b/test/diary_test.dart @@ -26,6 +26,7 @@ void main() { autocompleteList: [], portions: [], wakeupExpanded: false, + moderationExpanded: false, moodExpanded: false); await tester.pumpWidget(