fix(diary): Meal change method fix

This commit is contained in:
2024-07-15 17:10:55 +03:00
parent 76c1effe12
commit ae213f39a5
5 changed files with 83 additions and 78 deletions

View File

@@ -57,14 +57,23 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
final int? diaryID = data['id'];
final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45);
final Meal currentMeal = diary.meals[0];
List<SelectionPopupModel> portions = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")];
List<SelectionPopupModel> portionList = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")];
List<SelectionPopupModel> mealList = [
SelectionPopupModel(title: "Прием пищи 1", id: 1),
SelectionPopupModel(title: "Прием пищи 2", id: 2),
SelectionPopupModel(title: "Прием пищи 3", id: 3),
SelectionPopupModel(title: "Прием пищи 4", id: 4),
SelectionPopupModel(title: "Прием пищи 5", id: 5),
SelectionPopupModel(title: "Прием пищи 6", id: 6),
];
emit(DiaryState.loaded(
diary: diary,
currentMeal: currentMeal,
portions: currentMeal.portions,
photos: currentMeal.photos,
portionList: portions,
portionController: portions[0],
portionList: portionList,
portionController: portionList[0],
mealList: mealList,
selectedMood: currentMeal.mood,
selectedSatiety: currentMeal.satiety,
commentController: TextEditingController(),
@@ -209,9 +218,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
Emitter<DiaryState> emit,
) async {
if (state is DiaryStateLoaded) {
var currentState = state as DiaryStateLoaded;
Meal? meal = currentState.diary.meals.firstWhere((meal) => meal.id == event.value.id);
final currentState = state as DiaryStateLoaded;
final Meal meal = currentState.diary.meals.firstWhere((meal) => meal.type == event.value.id);
DiaryStateLoaded updatedState = currentState.copyWith(
currentMeal: meal,
portions: meal.portions,