diff --git a/lib/features/diary/presentation/bloc/diary_bloc.dart b/lib/features/diary/presentation/bloc/diary_bloc.dart index 8cebe1a..c50210b 100644 --- a/lib/features/diary/presentation/bloc/diary_bloc.dart +++ b/lib/features/diary/presentation/bloc/diary_bloc.dart @@ -57,14 +57,23 @@ class DiaryBloc extends Bloc { final int? diaryID = data['id']; final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45); final Meal currentMeal = diary.meals[0]; - List portions = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")]; + List portionList = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")]; + List 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 { Emitter 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, diff --git a/lib/features/diary/presentation/bloc/diary_event.dart b/lib/features/diary/presentation/bloc/diary_event.dart index eb4742e..d663752 100644 --- a/lib/features/diary/presentation/bloc/diary_event.dart +++ b/lib/features/diary/presentation/bloc/diary_event.dart @@ -110,11 +110,10 @@ class ProductInput extends DiaryEvent { } class ChangeMeal extends DiaryEvent { - ChangeMeal({required this.value, required this.meals}); - Meal value; - List? meals; + ChangeMeal({required this.value}); + SelectionPopupModel value; @override - List get props => [value, meals]; + List get props => [value]; } class ClearInput extends DiaryEvent { diff --git a/lib/features/diary/presentation/bloc/diary_state.dart b/lib/features/diary/presentation/bloc/diary_state.dart index 957dafc..fa49016 100644 --- a/lib/features/diary/presentation/bloc/diary_state.dart +++ b/lib/features/diary/presentation/bloc/diary_state.dart @@ -23,6 +23,7 @@ abstract class DiaryState with _$DiaryState { required List consumedChartValues, required List portions, required List photos, + required List mealList, required List portionList, required Meal currentMeal, required SelectionPopupModel portionController, diff --git a/lib/features/diary/presentation/bloc/diary_state.freezed.dart b/lib/features/diary/presentation/bloc/diary_state.freezed.dart index 3293104..2ecc30d 100644 --- a/lib/features/diary/presentation/bloc/diary_state.freezed.dart +++ b/lib/features/diary/presentation/bloc/diary_state.freezed.dart @@ -28,6 +28,7 @@ mixin _$DiaryState { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -64,6 +65,7 @@ mixin _$DiaryState { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -100,6 +102,7 @@ mixin _$DiaryState { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -218,6 +221,7 @@ class _$DiaryStateImpl implements _DiaryState { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -257,6 +261,7 @@ class _$DiaryStateImpl implements _DiaryState { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -296,6 +301,7 @@ class _$DiaryStateImpl implements _DiaryState { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -416,6 +422,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -455,6 +462,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -494,6 +502,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -580,6 +589,7 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -623,6 +633,7 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res> Object? consumedChartValues = null, Object? portions = null, Object? photos = null, + Object? mealList = null, Object? portionList = null, Object? currentMeal = null, Object? portionController = null, @@ -673,6 +684,10 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res> ? _value._photos : photos // ignore: cast_nullable_to_non_nullable as List, + mealList: null == mealList + ? _value._mealList + : mealList // ignore: cast_nullable_to_non_nullable + as List, portionList: null == portionList ? _value._portionList : portionList // ignore: cast_nullable_to_non_nullable @@ -784,6 +799,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { required final List consumedChartValues, required final List portions, required final List photos, + required final List mealList, required final List portionList, required this.currentMeal, required this.portionController, @@ -809,6 +825,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { _consumedChartValues = consumedChartValues, _portions = portions, _photos = photos, + _mealList = mealList, _portionList = portionList; @override @@ -858,6 +875,14 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { return EqualUnmodifiableListView(_photos); } + final List _mealList; + @override + List get mealList { + if (_mealList is EqualUnmodifiableListView) return _mealList; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_mealList); + } + final List _portionList; @override List get portionList { @@ -907,7 +932,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { @override String toString() { - return 'DiaryState.loaded(diary: $diary, diaryDate: $diaryDate, autocompleteList: $autocompleteList, recommendedChartValues: $recommendedChartValues, consumedChartValues: $consumedChartValues, portions: $portions, photos: $photos, portionList: $portionList, currentMeal: $currentMeal, portionController: $portionController, wakeupController: $wakeupController, retireController: $retireController, mealTimeController: $mealTimeController, commentController: $commentController, productNameController: $productNameController, productQuantityController: $productQuantityController, caloriesController: $caloriesController, fatsController: $fatsController, proteinsController: $proteinsController, carbsController: $carbsController, selectedMood: $selectedMood, selectedSatiety: $selectedSatiety, wakeupExpanded: $wakeupExpanded, moderationExpanded: $moderationExpanded, moodExpanded: $moodExpanded, isLoading: $isLoading, isAdded: $isAdded)'; + return 'DiaryState.loaded(diary: $diary, diaryDate: $diaryDate, autocompleteList: $autocompleteList, recommendedChartValues: $recommendedChartValues, consumedChartValues: $consumedChartValues, portions: $portions, photos: $photos, mealList: $mealList, portionList: $portionList, currentMeal: $currentMeal, portionController: $portionController, wakeupController: $wakeupController, retireController: $retireController, mealTimeController: $mealTimeController, commentController: $commentController, productNameController: $productNameController, productQuantityController: $productQuantityController, caloriesController: $caloriesController, fatsController: $fatsController, proteinsController: $proteinsController, carbsController: $carbsController, selectedMood: $selectedMood, selectedSatiety: $selectedSatiety, wakeupExpanded: $wakeupExpanded, moderationExpanded: $moderationExpanded, moodExpanded: $moodExpanded, isLoading: $isLoading, isAdded: $isAdded)'; } @override @@ -926,6 +951,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { .equals(other._consumedChartValues, _consumedChartValues) && const DeepCollectionEquality().equals(other._portions, _portions) && const DeepCollectionEquality().equals(other._photos, _photos) && + const DeepCollectionEquality().equals(other._mealList, _mealList) && const DeepCollectionEquality() .equals(other._portionList, _portionList) && (identical(other.currentMeal, currentMeal) || @@ -978,6 +1004,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { const DeepCollectionEquality().hash(_consumedChartValues), const DeepCollectionEquality().hash(_portions), const DeepCollectionEquality().hash(_photos), + const DeepCollectionEquality().hash(_mealList), const DeepCollectionEquality().hash(_portionList), currentMeal, portionController, @@ -1020,6 +1047,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -1051,6 +1079,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { consumedChartValues, portions, photos, + mealList, portionList, currentMeal, portionController, @@ -1086,6 +1115,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -1117,6 +1147,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { consumedChartValues, portions, photos, + mealList, portionList, currentMeal, portionController, @@ -1152,6 +1183,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -1185,6 +1217,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { consumedChartValues, portions, photos, + mealList, portionList, currentMeal, portionController, @@ -1256,6 +1289,7 @@ abstract class DiaryStateLoaded implements DiaryState { required final List consumedChartValues, required final List portions, required final List photos, + required final List mealList, required final List portionList, required final Meal currentMeal, required final SelectionPopupModel portionController, @@ -1284,6 +1318,7 @@ abstract class DiaryStateLoaded implements DiaryState { List get consumedChartValues; List get portions; List get photos; + List get mealList; List get portionList; Meal get currentMeal; SelectionPopupModel get portionController; @@ -1385,6 +1420,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -1424,6 +1460,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, @@ -1463,6 +1500,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError { List consumedChartValues, List portions, List photos, + List mealList, List portionList, Meal currentMeal, SelectionPopupModel portionController, diff --git a/lib/features/diary/presentation/pages/diary_screen.dart b/lib/features/diary/presentation/pages/diary_screen.dart index 8dcdbb7..422d8bc 100644 --- a/lib/features/diary/presentation/pages/diary_screen.dart +++ b/lib/features/diary/presentation/pages/diary_screen.dart @@ -247,9 +247,7 @@ class DiaryScreen extends StatelessWidget { borderRadius: BorderRadiusStyle.roundedBorder5, ), child: Center( - child: CircularProgressIndicator( - color: appTheme - .blueGray300), // Замените на свой прелоадер при необходимости + child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости ), ), ], @@ -273,8 +271,7 @@ class DiaryScreen extends StatelessWidget { _buildMeal(BuildContext context, DiaryStateLoaded state) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; - List _options = - state.autocompleteList.map((dynamic item) => item as String).toList(); + List _options = state.autocompleteList.map((dynamic item) => item as String).toList(); FocusNode focusNodeName = FocusNode(); return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -318,9 +315,7 @@ class DiaryScreen extends StatelessWidget { onTap: () => _selectMealTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: state.mealTimeController - ?.format(context) - .toString(), + hintText: state.mealTimeController?.format(context).toString(), autofocus: false, ), ), @@ -342,14 +337,13 @@ class DiaryScreen extends StatelessWidget { return null; }, builder: (context, diary) { - List meals = mealsToDropdown(diary!.meals); return CustomDropDown( - hintText: meals[0].title, - items: meals, + items: state.mealList, contentPadding: EdgeInsets.symmetric( horizontal: 10.h, vertical: 9.v, ), + defaultValue: state.mealList[0], onChanged: changeMeal(context, state), ); }, @@ -457,9 +451,7 @@ class DiaryScreen extends StatelessWidget { SizedBox(height: 30.v), _buildAddProduct(context, state), SizedBox(height: 30.v), - ...state.portions - .map((portion) => _buildProduct(context, portion)) - .toList(), + ...state.portions.map((portion) => _buildProduct(context, portion)).toList(), SizedBox(height: 30.v), /*...state.photos != null ? state.photos!.isEmpty @@ -616,8 +608,7 @@ class DiaryScreen extends StatelessWidget { popDialog(BuildContext dialogContext) { return () { - Navigator.of(dialogContext) - .pop(); // Dismiss the dialog on Cancel button press + Navigator.of(dialogContext).pop(); // Dismiss the dialog on Cancel button press }; } @@ -627,8 +618,7 @@ class DiaryScreen extends StatelessWidget { }; } - selectProduct(AutocompleteOnSelected onSelected, String option, - DiaryStateLoaded state) { + selectProduct(AutocompleteOnSelected onSelected, String option, DiaryStateLoaded state) { state.productNameController.text = option; return () { onSelected(option); @@ -653,9 +643,7 @@ class DiaryScreen extends StatelessWidget { changeMeal(BuildContext context, DiaryStateLoaded state) { return (value) { - context - .read() - .add(ChangeMeal(meals: state.diary.meals, value: value)); + context.read().add(ChangeMeal(value: value)); }; } @@ -672,8 +660,7 @@ class DiaryScreen extends StatelessWidget { return CarouselSlider( options: CarouselOptions(height: 340.0), items: state.currentMeal.photos.map((photo) { - return _buildPhoto( - context, photo); // Assuming photos are stored as strings + return _buildPhoto(context, photo); // Assuming photos are stored as strings }).toList(), ); } @@ -699,9 +686,7 @@ class DiaryScreen extends StatelessWidget { top: 5.v, ), child: Text( - portion.productName.length > 8 - ? portion.productName.substring(0, 8) - : portion.productName, + portion.productName.length > 8 ? portion.productName.substring(0, 8) : portion.productName, style: CustomTextStyles.titleMedium16, ), ), @@ -773,15 +758,12 @@ class DiaryScreen extends StatelessWidget { removePhoto(BuildContext context, Photo photo) { return () { - context - .read() - .add(RemoveImageEvent(photo.id.toString(), photo.path)); + context.read().add(RemoveImageEvent(photo.id.toString(), photo.path)); }; } _buildNutritionChart(BuildContext context, DiaryStateLoaded state) { - final List recommendedValues = state - .recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы + final List recommendedValues = state.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы final List consumedValues = state.consumedChartValues; // return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -845,10 +827,7 @@ class DiaryScreen extends StatelessWidget { barRods: [ BarChartRodData( toY: consumedValues[0] / recommendedValues[0] * 100, - color: checkConsumedValues( - [recommendedValues[0]], [consumedValues[1]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[0]], [consumedValues[1]]) ? Colors.red : Colors.blue, ), ], ), @@ -857,10 +836,7 @@ class DiaryScreen extends StatelessWidget { barRods: [ BarChartRodData( toY: consumedValues[1] / recommendedValues[1] * 100, - color: checkConsumedValues( - [recommendedValues[1]], [consumedValues[1]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[1]], [consumedValues[1]]) ? Colors.red : Colors.blue, ), ], ), @@ -869,10 +845,7 @@ class DiaryScreen extends StatelessWidget { barRods: [ BarChartRodData( toY: consumedValues[2] / recommendedValues[2] * 100, - color: checkConsumedValues( - [recommendedValues[2]], [consumedValues[2]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[2]], [consumedValues[2]]) ? Colors.red : Colors.blue, ), ], ), @@ -881,10 +854,7 @@ class DiaryScreen extends StatelessWidget { barRods: [ BarChartRodData( toY: consumedValues[3] / recommendedValues[3] * 100, - color: checkConsumedValues( - [recommendedValues[3]], [consumedValues[3]]) - ? Colors.red - : Colors.blue, + color: checkConsumedValues([recommendedValues[3]], [consumedValues[3]]) ? Colors.red : Colors.blue, ), ], ), @@ -1075,9 +1045,7 @@ class DiaryScreen extends StatelessWidget { r"Подъем \ отход ко сну", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.wakeupExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), + Icon(state.wakeupExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], ), ), @@ -1091,8 +1059,7 @@ class DiaryScreen extends StatelessWidget { onTap: () => _selectWakeupTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: - state.wakeupController?.format(context).toString(), + hintText: state.wakeupController?.format(context).toString(), prefix: Icon(Icons.sunny), autofocus: false, ), @@ -1103,8 +1070,7 @@ class DiaryScreen extends StatelessWidget { onTap: () => _selectRetireTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: - state.retireController?.format(context).toString(), + hintText: state.retireController?.format(context).toString(), prefix: Icon(Icons.bed), autofocus: false, ), @@ -1151,8 +1117,7 @@ class DiaryScreen extends StatelessWidget { }; } - Function() sendFinishDayData( - BuildContext dialogContext, BuildContext context) { + Function() sendFinishDayData(BuildContext dialogContext, BuildContext context) { return () { closeDialog(dialogContext); context.read().add(FinishDay()); @@ -1195,9 +1160,7 @@ class DiaryScreen extends StatelessWidget { "Ваше настроение после приема пищи", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.moodExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), + Icon(state.moodExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], ), ), @@ -1257,8 +1220,7 @@ class DiaryScreen extends StatelessWidget { }; } - Future _selectWakeupTime( - BuildContext context, DiaryStateLoaded state) async { + Future _selectWakeupTime(BuildContext context, DiaryStateLoaded state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.wakeupController ?? TimeOfDay.now(), @@ -1268,8 +1230,7 @@ class DiaryScreen extends StatelessWidget { } } - Future _selectRetireTime( - BuildContext context, DiaryStateLoaded state) async { + Future _selectRetireTime(BuildContext context, DiaryStateLoaded state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.retireController ?? TimeOfDay.now(), @@ -1279,8 +1240,7 @@ class DiaryScreen extends StatelessWidget { } } - Future _selectMealTime( - BuildContext context, DiaryStateLoaded state) async { + Future _selectMealTime(BuildContext context, DiaryStateLoaded state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.mealTimeController ?? TimeOfDay.now(), @@ -1291,8 +1251,7 @@ class DiaryScreen extends StatelessWidget { } } -bool checkConsumedValues( - List recommendedValues, List consumedValues) { +bool checkConsumedValues(List recommendedValues, List consumedValues) { for (int i = 0; i < recommendedValues.length; i++) { if (consumedValues[i] > recommendedValues[i]) { // Если хотя бы одно потребленное значение превышает рекомендованное