import 'package:collection/collection.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart'; import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/add_product_button_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/chosen_diet_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/chosen_plan_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/comment_container.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/meal_button_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/meal_comment_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/mood_rating_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/photo_gallery_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/products_list_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/satiety_rating_widget.dart'; import 'package:eatvio_app/features/diary/presentation/widgets/time_of_meal_picker_widget.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class MealWidget extends StatefulWidget { const MealWidget({super.key, required this.showMood, required this.showAddButton}); final bool showMood; final bool showAddButton; @override State createState() => _MealWidgetState(); } class _MealWidgetState extends State { @override Widget build(BuildContext context) { final s = S.of(context); return Material( borderRadius: BorderRadius.circular(20), color: Colors.white, child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( 'Прием пищи', style: TextStyle( color: Color(0xFF323F4B), fontSize: 18, fontWeight: FontWeight.w500, ), ), const SizedBox(height: 16), const Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ MealButtonWidget(mealNumber: 1), MealButtonWidget(mealNumber: 2), MealButtonWidget(mealNumber: 3), MealButtonWidget(mealNumber: 4), MealButtonWidget(mealNumber: 5), ], ), const SizedBox(height: 12), const TimeOfMealPickerWidget(), const ChosenDietWidget(), const ChosenPlanWidget(), const ProductsListWidget(), if (widget.showAddButton) ...[ const SizedBox(height: 12), const AddProductButtonWidget(), ], const SizedBox(height: 12), const PhotoGalleryWidget(), const SizedBox(height: 12), const SatietyRatingWidget(), if (widget.showMood) ...[ const SizedBox(height: 12), const MoodRatingWidget(), ], BlocBuilder( builder: (context, state) { if (state is DiaryStateLoaded && state.isConsultantView && !state.isDiaryCommented) { return MealCommentWidget(selectedMeal: state.selectedMeal); } return const SizedBox.shrink(); }, ), BlocBuilder( builder: (context, state) { if (state is DiaryStateLoaded) { final consultantCommentOfMeal = state.consultantReview?.consultantComments.mealsComments.firstWhereOrNull( (element) => element.typeNo == state.selectedMeal, ); if (consultantCommentOfMeal != null) { return Column( children: [ Text( '${s.mealComment} ${state.selectedMeal}', style: TextStyles.textLSemibold.copyWith(color: appTheme.black), ), const SizedBox(height: 12), CommentContainer(comment: consultantCommentOfMeal.comment), ], ); } } return const SizedBox.shrink(); }, ) ], ), ), ); } }