From 2d15e9ea4ecb8b90ee1327764c9cb71b9485f5a0 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 25 Jul 2024 10:36:14 +0300 Subject: [PATCH] refactor(diary): Diary updated on method call success --- .../diary/presentation/bloc/diary_bloc.dart | 33 ++++--------------- .../diary/presentation/bloc/diary_event.dart | 3 +- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/lib/features/diary/presentation/bloc/diary_bloc.dart b/lib/features/diary/presentation/bloc/diary_bloc.dart index a54ed15e..cc0682a2 100644 --- a/lib/features/diary/presentation/bloc/diary_bloc.dart +++ b/lib/features/diary/presentation/bloc/diary_bloc.dart @@ -43,9 +43,6 @@ class DiaryBloc extends Bloc { ); on(_finishDay); on(_sendModeration); - on( - reloadScreen, - ); on(_clearInput); } @@ -189,21 +186,6 @@ class DiaryBloc extends Bloc { } } - refreshScreen( - int mealID, - DiaryEvent event, - Emitter emit, - ) async { - await reloadScreen(event, emit); - } - - reloadScreen( - DiaryEvent event, - Emitter emit, - ) async { - print("Reloading..."); - } - Future _changeSatiety( ChangeSatiety event, Emitter emit, @@ -341,20 +323,14 @@ class DiaryBloc extends Bloc { if (state is DiaryStateLoaded) { var currentState = state as DiaryStateLoaded; - Map data = await diaryRepository.addPortion( + await diaryRepository.addPortion( currentState.diary.id, currentState.currentMeal.id, currentState.product_nameController.text, currentState.portionController.title, int.parse(currentState.productQuantityController.text), ); - List newPortions = currentState.portions; - - final Portion newPortion = data['portion'] ?? - new Portion(id: 1, portion: 'gr', product_name: '1', quantity: 1); - newPortions.add(newPortion); - emit(currentState.copyWith(isAdded: true, portions: newPortions)); - //TODO update screen after addPortion() call + add(LoadDiary()); } } @@ -370,7 +346,7 @@ class DiaryBloc extends Bloc { event.portionId, ); } - //TODO update screen after _removePortion() call + add(LoadDiary()); } Future _uploadImages( @@ -386,6 +362,7 @@ class DiaryBloc extends Bloc { currentState.diary.id, currentState.currentMeal.id, ); + add(LoadDiary()); } } @@ -463,6 +440,7 @@ class DiaryBloc extends Bloc { int.parse(event.photoID), event.path, ); + add(LoadDiary()); } } @@ -476,6 +454,7 @@ class DiaryBloc extends Bloc { currentState.retireController, currentState.commentController.text, ); + add(LoadDiary()); } } diff --git a/lib/features/diary/presentation/bloc/diary_event.dart b/lib/features/diary/presentation/bloc/diary_event.dart index d6637528..490fa0c6 100644 --- a/lib/features/diary/presentation/bloc/diary_event.dart +++ b/lib/features/diary/presentation/bloc/diary_event.dart @@ -157,5 +157,6 @@ class SendModeration extends DiaryEvent { String fatsOn100gr; String carbohydratesOn100gr; @override - List get props => [name, energyOn100gr, proteinsOn100gr, fatsOn100gr, carbohydratesOn100gr]; + List get props => + [name, energyOn100gr, proteinsOn100gr, fatsOn100gr, carbohydratesOn100gr]; }