forked from eatvio/eatvio_app
fix(diary): Fix
This commit is contained in:
@@ -42,6 +42,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
on<FinishDay>(_finishDay);
|
||||
on<SendModeration>(_sendModeration);
|
||||
on<ClearInput>(_clearInput);
|
||||
on<ConfirmPortion>(_confirmPortion);
|
||||
}
|
||||
|
||||
loadDiary(
|
||||
@@ -329,7 +330,6 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
await diaryRepository.addPortion(
|
||||
currentState.diary.id,
|
||||
currentState.currentMeal.id,
|
||||
@@ -484,6 +484,26 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
SelectionPopupModel(id: 1, title: "грамм"),
|
||||
];
|
||||
}
|
||||
|
||||
FutureOr<void> _confirmPortion(ConfirmPortion event, Emitter<DiaryState> emit) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
final updatedPortions = currentState.portions.map((portion) {
|
||||
if (portion.id == event.id) {
|
||||
return portion.copyWith(from_diet: !portion.from_diet);
|
||||
}
|
||||
if (!portion.from_diet) add(RemovePortionEvent(portion.id));
|
||||
return portion;
|
||||
}).toList();
|
||||
|
||||
final updatedState = currentState.copyWith(portions: updatedPortions);
|
||||
|
||||
emit(updatedState);
|
||||
|
||||
add(LoadDiary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int convertToInt(dynamic value) {
|
||||
|
||||
@@ -180,6 +180,14 @@ class RefreshEvent extends DiaryEvent {
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ConfirmPortion extends DiaryEvent {
|
||||
ConfirmPortion(this.id);
|
||||
int id;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
}
|
||||
|
||||
class SendModeration extends DiaryEvent {
|
||||
SendModeration({
|
||||
required this.name,
|
||||
|
||||
Reference in New Issue
Block a user