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,
|
||||
|
||||
@@ -271,7 +271,7 @@ class DiaryScreen extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
backgroundColor: appTheme.blueA400,
|
||||
onPressed: () => addProduct,
|
||||
onPressed: () => addProduct(context),
|
||||
label: Text(
|
||||
'Добавить продукт',
|
||||
style: theme.textTheme.titleSmall,
|
||||
@@ -281,9 +281,7 @@ class DiaryScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
addProduct(BuildContext context) {
|
||||
return () {
|
||||
context.read<DiaryBloc>().add(AddPortionEvent());
|
||||
};
|
||||
context.read<DiaryBloc>().add(AddPortionEvent());
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
@@ -778,7 +776,7 @@ class DiaryScreen extends StatelessWidget {
|
||||
),
|
||||
Spacer(),
|
||||
GestureDetector(
|
||||
onTap: removePortion(context, portion),
|
||||
onTap: () => removePortion(context, portion),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: Icon(
|
||||
@@ -811,7 +809,7 @@ class DiaryScreen extends StatelessWidget {
|
||||
children: [
|
||||
Checkbox(
|
||||
value: !portion.from_diet,
|
||||
onChanged: (bool? value) {},
|
||||
onChanged: (bool? value) => context.read<DiaryBloc>().add(ConfirmPortion(portion.id)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
@@ -819,10 +817,11 @@ class DiaryScreen extends StatelessWidget {
|
||||
top: 5.v,
|
||||
),
|
||||
child: Text(
|
||||
portion.product_name.length > 8 ? portion.product_name.substring(0, 8) : portion.product_name,
|
||||
portion.product_name.length > 18 ? portion.product_name.substring(0, 18) : portion.product_name,
|
||||
style: CustomTextStyles.titleMedium16,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20.h,
|
||||
@@ -833,17 +832,6 @@ class DiaryScreen extends StatelessWidget {
|
||||
portion.quantity.toString() + ' ' + portion.portion.toString().tr,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => removePortion(context, portion), // Обернуть в лямбду
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: appTheme.blueGray300,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user