refactor(diary): Diary updated on method call success

This commit is contained in:
2024-07-25 10:36:14 +03:00
parent 0671c5d072
commit 2d15e9ea4e
2 changed files with 8 additions and 28 deletions

View File

@@ -43,9 +43,6 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
);
on<FinishDay>(_finishDay);
on<SendModeration>(_sendModeration);
on<RefreshEvent>(
reloadScreen,
);
on<ClearInput>(_clearInput);
}
@@ -189,21 +186,6 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
}
}
refreshScreen(
int mealID,
DiaryEvent event,
Emitter<DiaryState> emit,
) async {
await reloadScreen(event, emit);
}
reloadScreen(
DiaryEvent event,
Emitter<DiaryState> emit,
) async {
print("Reloading...");
}
Future<void> _changeSatiety(
ChangeSatiety event,
Emitter<DiaryState> emit,
@@ -341,20 +323,14 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
if (state is DiaryStateLoaded) {
var currentState = state as DiaryStateLoaded;
Map<String, Portion> 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<Portion> 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<DiaryEvent, DiaryState> {
event.portionId,
);
}
//TODO update screen after _removePortion() call
add(LoadDiary());
}
Future<void> _uploadImages(
@@ -386,6 +362,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
currentState.diary.id,
currentState.currentMeal.id,
);
add(LoadDiary());
}
}
@@ -463,6 +440,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
int.parse(event.photoID),
event.path,
);
add(LoadDiary());
}
}
@@ -476,6 +454,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
currentState.retireController,
currentState.commentController.text,
);
add(LoadDiary());
}
}

View File

@@ -157,5 +157,6 @@ class SendModeration extends DiaryEvent {
String fatsOn100gr;
String carbohydratesOn100gr;
@override
List<Object?> get props => [name, energyOn100gr, proteinsOn100gr, fatsOn100gr, carbohydratesOn100gr];
List<Object?> get props =>
[name, energyOn100gr, proteinsOn100gr, fatsOn100gr, carbohydratesOn100gr];
}