From 55e3abec99518051fca5190f38c35069afcf3fb6 Mon Sep 17 00:00:00 2001 From: Username1548 Date: Mon, 14 Jul 2025 12:15:26 +0700 Subject: [PATCH 1/7] feat(personal diets): added personal diet option to plans --- lib/core/const.dart | 2 + lib/core/theme/theme_helper.dart | 4 +- lib/core/widgets/option_widget.dart | 52 ++++++++++++++++-- .../presentation/cubit/create_plan_cubit.dart | 11 ++++ .../presentation/widgets/option_widget.dart | 54 +++++++++---------- .../feed/models/plan_pagination_model.dart | 10 +++- .../presentation/info_by_order_screen.dart | 1 + .../presentation/pages/about_plan_screen.dart | 3 ++ lib/generated/intl/messages_en.dart | 3 ++ lib/generated/l10n.dart | 10 ++++ lib/l10n/intl_en.arb | 3 +- 11 files changed, 118 insertions(+), 35 deletions(-) diff --git a/lib/core/const.dart b/lib/core/const.dart index 618a9866..9a1275d6 100644 --- a/lib/core/const.dart +++ b/lib/core/const.dart @@ -1,4 +1,6 @@ String baseUrl = 'https://eatvio.ru'; +// String baseUrl = 'https://dev2.eatvio.com'; + const List durationValues = [7, 14, 21]; diff --git a/lib/core/theme/theme_helper.dart b/lib/core/theme/theme_helper.dart index 3b2a063d..81087ec9 100644 --- a/lib/core/theme/theme_helper.dart +++ b/lib/core/theme/theme_helper.dart @@ -101,7 +101,7 @@ class PrimaryColors { // Blue Color get blue400 => const Color(0XFF43A6F2); - Color get blueA400 => const Color(0XFF2F80ED); + Color get blueA400 => const Color(0XFF2F80ED); // BlueGray Color get blueGray400 => const Color(0XFF7B8794); @@ -148,6 +148,8 @@ class PrimaryColors { Color get green => const Color(0XFF0BB450); + Color get transparentGreen => const Color.fromARGB(12, 1, 154, 63); + // LightGreen Color get lightGreen300 => const Color(0XFFB2DF8A); diff --git a/lib/core/widgets/option_widget.dart b/lib/core/widgets/option_widget.dart index 779f6c38..bed09c27 100644 --- a/lib/core/widgets/option_widget.dart +++ b/lib/core/widgets/option_widget.dart @@ -9,9 +9,10 @@ import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; class OptionWidget extends StatelessWidget { - const OptionWidget({super.key, required this.option, this.disableDuration = false}); + const OptionWidget({super.key, required this.option, this.disableDuration = false, required this.duration}); final PacketOptions? option; final bool disableDuration; + final int duration; @override Widget build(BuildContext context) { if (option == null) { @@ -34,8 +35,12 @@ class OptionWidget extends StatelessWidget { ), const SizedBox(height: 12), if (!disableDuration) ...[ - const _OptionDurationWidget(duration: 7), - const SizedBox(height: 16), + _OptionDurationWidget(duration: duration), + SizedBox(height: option?.hasPersonalDiet ?? false ? 8 : 12), + ], + if ((option?.hasPersonalDiet ?? false) && !disableDuration) ...[ + const _OptionHasPersonalDietWidget(), + const SizedBox(height: 12), ], const CustomDivider(), const SizedBox(height: 16), @@ -52,7 +57,6 @@ class OptionWidget extends StatelessWidget { } } - class _OptionDurationWidget extends StatelessWidget { const _OptionDurationWidget({required this.duration}); final int duration; @@ -92,3 +96,43 @@ class _OptionDurationWidget extends StatelessWidget { ); } } + +class _OptionHasPersonalDietWidget extends StatelessWidget { + const _OptionHasPersonalDietWidget(); + + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Container( + decoration: BoxDecoration(borderRadius: BorderRadius.circular(4), color: appTheme.transparentGreen), + child: Row( + children: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 4), + child: Container( + width: 4, + height: 20, + decoration: BoxDecoration( + color: appTheme.green, + borderRadius: const BorderRadius.only( + topRight: Radius.circular(100), + bottomRight: Radius.circular(100), + ), + ), + ), + ), + const SizedBox( + width: 12, + ), + Text( + s.personalDietCreating, + style: TextStyles.textSMedium.copyWith(color: appTheme.black), + ), + const SizedBox( + width: 12, + ), + ], + ), + ); + } +} diff --git a/lib/features/create_plan/presentation/cubit/create_plan_cubit.dart b/lib/features/create_plan/presentation/cubit/create_plan_cubit.dart index 96385904..2289b31f 100644 --- a/lib/features/create_plan/presentation/cubit/create_plan_cubit.dart +++ b/lib/features/create_plan/presentation/cubit/create_plan_cubit.dart @@ -67,6 +67,13 @@ class CreatePlanCubit extends Cubit { validateSelectedOptionItems(); } + void togglePersonalizedDietOptionState() { + final options = [...state.planData.options]; + options[state.selectedOptionIndex ?? 0] = + options[state.selectedOptionIndex ?? 0].copyWith(hasPersonalDiet: !options[state.selectedOptionIndex ?? 0].hasPersonalDiet); + emit(state.copyWith(planData: state.planData.copyWith(options: options))); + } + void setDuration(int index) { emit( state.copyWith( @@ -418,18 +425,21 @@ class CreatePlanCubit extends Cubit { 'price': int.parse((state.planData.options[0].price as double).toStringAsFixed(0)), 'description_md': state.planData.options[0].description, 'items': Map.fromIterable(state.planData.options[0].items), + 'has_personal_diet': state.planData.options[0].hasPersonalDiet ? '1' : '0', }, 'packet2_options': { 'short': state.planData.options[1].short, 'price': int.parse((state.planData.options[1].price as double).toStringAsFixed(0)), 'description_md': state.planData.options[1].description, 'items': Map.fromIterable(state.planData.options[1].items), + 'has_personal_diet': state.planData.options[1].hasPersonalDiet ? '1' : '0', }, 'packet3_options': { 'short': state.planData.options[2].short, 'price': int.parse((state.planData.options[2].price as double).toStringAsFixed(0)), 'description_md': state.planData.options[2].description, 'items': Map.fromIterable(state.planData.options[2].items), + 'has_personal_diet': state.planData.options[2].hasPersonalDiet ? '1' : '0', }, }); } else { @@ -440,6 +450,7 @@ class CreatePlanCubit extends Cubit { 'price': int.parse((state.planData.options[0].price as double).toStringAsFixed(0)), 'description_md': state.planData.options[0].description, 'items': Map.fromIterable(state.planData.options[0].items), + 'has_personal_diet': state.planData.options[0].hasPersonalDiet ? '1' : '0', }, }); } diff --git a/lib/features/create_plan/presentation/widgets/option_widget.dart b/lib/features/create_plan/presentation/widgets/option_widget.dart index 42362e96..24cde52b 100644 --- a/lib/features/create_plan/presentation/widgets/option_widget.dart +++ b/lib/features/create_plan/presentation/widgets/option_widget.dart @@ -90,7 +90,7 @@ class _OptionWidgetState extends State { 2 => thirdOptionCustomerPriceController, _ => secondOptionCustomerPriceController, }; - + final price = double.tryParse(customerPriceController.text.replaceAll('₽', '')); creatorPriceController.text = '${((price ?? 0) * 0.8).toStringAsFixed(2)}₽'; firstOptionTitleController.text = state.planData.options[selectedOptionIndex].short; @@ -255,33 +255,31 @@ class _OptionWidgetState extends State { ), const SizedBox(height: 16), const CustomDivider(), - // const SizedBox(height: 16), - // Row( - // children: [ - // Checkbox( - // value: isChecked, - // activeColor: appTheme.gray, - // checkColor: appTheme.gray, - // fillColor: const WidgetStatePropertyAll(Colors.transparent), - // side: WidgetStateBorderSide.resolveWith( - // (Set states) { - // return BorderSide(width: 1, color: appTheme.gray); - // }, - // ), - // onChanged: (bool? value) { - // setState(() { - // isChecked = value ?? false; - // }); - // }, - // ), - // Expanded( - // child: Text( - // s.option_personal_diet_desc, - // style: TextStyles.textMMedium.copyWith(color: appTheme.black), - // ), - // ), - // ], - // ), + const SizedBox(height: 16), + Row( + children: [ + Checkbox( + value: state.planData.options[selectedOptionIndex].hasPersonalDiet, + activeColor: appTheme.gray, + checkColor: appTheme.gray, + fillColor: const WidgetStatePropertyAll(Colors.transparent), + side: WidgetStateBorderSide.resolveWith( + (Set states) { + return BorderSide(width: 1, color: appTheme.gray); + }, + ), + onChanged: (bool? value) { + context.read().togglePersonalizedDietOptionState(); + }, + ), + Expanded( + child: Text( + s.option_personal_diet_desc, + style: TextStyles.textMMedium.copyWith(color: appTheme.black), + ), + ), + ], + ), ], ), ); diff --git a/lib/features/feed/models/plan_pagination_model.dart b/lib/features/feed/models/plan_pagination_model.dart index 728ff0b7..6c948685 100644 --- a/lib/features/feed/models/plan_pagination_model.dart +++ b/lib/features/feed/models/plan_pagination_model.dart @@ -67,11 +67,19 @@ abstract class PacketOptions with _$PacketOptions { @JsonKey(name: "price") required dynamic price, @JsonKey(name: "short") required String short, @JsonKey(name: "description_md") required String description, + @JsonKey(name: "has_personal_diet", fromJson: _parseHasPersonalDietField) required bool hasPersonalDiet, }) = _PacketOptions; factory PacketOptions.fromJson(Map json) => _$PacketOptionsFromJson(json); - factory PacketOptions.empty() => PacketOptions(items: [], price: double.parse('1200'), short: '', description: ''); + factory PacketOptions.empty() => PacketOptions(items: [], price: double.parse('1200'), short: '', description: '', hasPersonalDiet: false); +} + +bool _parseHasPersonalDietField(dynamic json) { + if (json == null) return false; + if (json == '1') return true; + if (json == '0') return false; + return json as bool; } List _parseItems(dynamic json) { diff --git a/lib/features/order_info/presentation/info_by_order_screen.dart b/lib/features/order_info/presentation/info_by_order_screen.dart index a1d94580..0aa5e6e7 100644 --- a/lib/features/order_info/presentation/info_by_order_screen.dart +++ b/lib/features/order_info/presentation/info_by_order_screen.dart @@ -169,6 +169,7 @@ class _InfoByOrderScreenContentState extends State { OptionWidget( option: chosenOption, disableDuration: true, + duration: plan.plan.duration, ), const SizedBox(height: 8), PlanState( diff --git a/lib/features/plans/presentation/pages/about_plan_screen.dart b/lib/features/plans/presentation/pages/about_plan_screen.dart index d2984b68..41610a38 100644 --- a/lib/features/plans/presentation/pages/about_plan_screen.dart +++ b/lib/features/plans/presentation/pages/about_plan_screen.dart @@ -505,12 +505,15 @@ class _AboutPlanScreenState extends State { switch (state.chosenOptionIndex) { 1 => OptionWidget( option: state.planModel?.packet2Options, + duration: state.planModel?.duration ?? 0, ), 2 => OptionWidget( option: state.planModel?.packet3Options, + duration: state.planModel?.duration ?? 0, ), _ => OptionWidget( option: state.planModel?.packet1Options, + duration: state.planModel?.duration ?? 0, ), }, const SizedBox( diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index e318c962..700d4b48 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -542,6 +542,9 @@ class MessageLookup extends MessageLookupByLibrary { "pcs": MessageLookupByLibrary.simpleMessage("шт"), "pending_payment": MessageLookupByLibrary.simpleMessage("Ожидается оплата"), "personal": MessageLookupByLibrary.simpleMessage("Персональные"), + "personalDietCreating": MessageLookupByLibrary.simpleMessage( + "Составление индивидуальной диеты", + ), "personal_diet_state": MessageLookupByLibrary.simpleMessage("Персональная"), "photo": MessageLookupByLibrary.simpleMessage("Фото"), "physical_fitness": MessageLookupByLibrary.simpleMessage( diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 9f338062..585a3154 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -3394,6 +3394,16 @@ class S { args: [], ); } + + /// `Составление индивидуальной диеты` + String get personalDietCreating { + return Intl.message( + 'Составление индивидуальной диеты', + name: 'personalDietCreating', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 96ddc4be..08ad7704 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -402,6 +402,7 @@ "allowAcessToGaleryDescription": "Предоставление доступа позволит вам добавлять фото к записям", "allowAccessToCamera": "Разрешите доступ к камере", "allowAccessToCameraDescription": "Предоставление доступа позволит вам делать фотографии и добавлять к записям", - "allowAccess": "Разрешить доступ" + "allowAccess": "Разрешить доступ", + "personalDietCreating": "Составление индивидуальной диеты" } From 5616bedd257387d24d18ae1bf3ca535baae5f1f8 Mon Sep 17 00:00:00 2001 From: Username1548 Date: Mon, 14 Jul 2025 13:44:44 +0700 Subject: [PATCH 2/7] feat(personalDiets): diets suggestions --- lib/core/app_router.dart | 7 ++ lib/core/const.dart | 4 +- lib/core/locator_service.dart | 6 ++ .../models/consultation_model.dart | 1 + .../presentation/widgets/my_diet_widget.dart | 6 +- .../cubit/personal_diet_suggestion_cubit.dart | 67 +++++++++++++++++++ .../cubit/personal_diet_suggestion_state.dart | 16 +++++ .../presentation/consultation_widget.dart | 58 ++++++++++++++++ .../personal_diet_suggestion_screen.dart | 66 ++++++++++++++++++ .../personal_diet_suggestion_repository.dart | 32 +++++++++ .../personal_diet_suggestion_service.dart | 33 +++++++++ lib/generated/intl/messages_en.dart | 3 + lib/generated/l10n.dart | 50 +++++++++++--- lib/l10n/intl_en.arb | 5 +- 14 files changed, 340 insertions(+), 14 deletions(-) create mode 100644 lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart create mode 100644 lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart create mode 100644 lib/features/personal_diet_suggestion/presentation/consultation_widget.dart create mode 100644 lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart create mode 100644 lib/features/personal_diet_suggestion/repository/personal_diet_suggestion_repository.dart create mode 100644 lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart diff --git a/lib/core/app_router.dart b/lib/core/app_router.dart index 223a8913..95f94c04 100644 --- a/lib/core/app_router.dart +++ b/lib/core/app_router.dart @@ -46,6 +46,7 @@ import 'package:eatvio_app/features/finances_and_consultations_archive/presentat import 'package:eatvio_app/features/my_finance/presentation/pages/user_finance_screen.dart'; import 'package:eatvio_app/features/my_plans/presentation/my_plans_screen.dart'; import 'package:eatvio_app/features/notifications/presentation/notifications_screen.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart'; import 'package:eatvio_app/features/plans/presentation/pages/about_plan_screen.dart'; import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart'; import 'package:eatvio_app/features/profile/presentation/pages/subs_screen.dart'; @@ -515,6 +516,12 @@ class AppRouter { name: MyRecipesScreen.name, builder: (context, state) => const MyRecipesScreen(), ), + + GoRoute( + path: PersonalDietSuggestionScreen.path, + name: PersonalDietSuggestionScreen.name, + builder: (context, state) => PersonalDietSuggestionScreen(dietId: state.extra as int,), + ), ], ); } diff --git a/lib/core/const.dart b/lib/core/const.dart index 31c47e9c..4f38a54e 100644 --- a/lib/core/const.dart +++ b/lib/core/const.dart @@ -1,5 +1,5 @@ -String baseUrl = 'https://eatvio.ru'; -// String baseUrl = 'https://dev2.eatvio.com'; +// String baseUrl = 'https://eatvio.ru'; +String baseUrl = 'https://dev2.eatvio.com'; const List durationValues = [7, 14, 21]; diff --git a/lib/core/locator_service.dart b/lib/core/locator_service.dart index 49c6c5dc..4d4a0712 100644 --- a/lib/core/locator_service.dart +++ b/lib/core/locator_service.dart @@ -81,6 +81,9 @@ import 'package:eatvio_app/features/my_plans/services/my_plans_service.dart'; import 'package:eatvio_app/features/notifications/repository/notifications_repository.dart'; import 'package:eatvio_app/features/notifications/service/notifications_service.dart'; import 'package:eatvio_app/features/order_info/cubit/order_info_cubit.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/repository/personal_diet_suggestion_repository.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart'; import 'package:eatvio_app/features/plans/repositories/plans_repository.dart'; import 'package:eatvio_app/features/plans/services/plans_service.dart'; import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_cubit.dart'; @@ -170,6 +173,7 @@ Future init() async { sl.registerFactory(() => ResetPasswordCubit(resetPasswordRepository: sl())); sl.registerFactory(() => BlogPostCubit(sl())); sl.registerFactory(() => BlockedUsersCubit(blockedUsersRepository: sl())); + sl.registerFactory(() => PersonalDietSuggestionCubit(dietRepository: sl(), personalDietSuggestionService: sl())); // Repository sl.registerLazySingleton(() => ChatRepository(chatService: sl())); @@ -201,6 +205,7 @@ Future init() async { sl.registerFactory(() => ResetPasswordRepository(resetPasswordService: sl())); sl.registerLazySingleton(() => BlockedUsersRepository(blockedUserService: sl())); sl.registerLazySingleton(() => CommentsRepository(service: sl())); + sl.registerLazySingleton(() => PersonalDietSuggestionRepository(personalDietSuggestionService: sl())); // Services sl.registerLazySingleton(() => ChatService(sl())); @@ -234,6 +239,7 @@ Future init() async { sl.registerLazySingleton(() => ResetPasswordService(sl())); sl.registerLazySingleton(() => BlockedUserService(sl())); sl.registerLazySingleton(() => CommentsService(sl())); + sl.registerLazySingleton(() => PersonalDietSuggestionService(sl())); // External sl.registerLazySingleton( diff --git a/lib/features/consultations/models/consultation_model.dart b/lib/features/consultations/models/consultation_model.dart index 59c48f09..c73a8d37 100644 --- a/lib/features/consultations/models/consultation_model.dart +++ b/lib/features/consultations/models/consultation_model.dart @@ -22,6 +22,7 @@ abstract class ConsultationModel with _$ConsultationModel { @JsonKey(name: 'end_date', fromJson: parseDate) required DateTime endDate, @JsonKey(name: 'consultant_id') required int consultantId, required List diaries, + @JsonKey(name: 'personal_diet_id') required int? personalDietId, }) = _ConsultationModel; factory ConsultationModel.fromJson(Map json) => _$ConsultationModelFromJson(json); diff --git a/lib/features/my_diets/presentation/widgets/my_diet_widget.dart b/lib/features/my_diets/presentation/widgets/my_diet_widget.dart index 965bd088..c5dd3cdf 100644 --- a/lib/features/my_diets/presentation/widgets/my_diet_widget.dart +++ b/lib/features/my_diets/presentation/widgets/my_diet_widget.dart @@ -16,6 +16,7 @@ import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_cubit.d import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_state.dart'; import 'package:eatvio_app/features/my_diets/presentation/widgets/diet_deleted_bottom_sheet.dart'; import 'package:eatvio_app/features/my_diets/presentation/widgets/diet_drafetd_bottom_sheet.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -89,7 +90,9 @@ class _MyDietWidgetState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: Html( - data: widget.diet.details.length > 200 ? '${widget.diet.details.substring(0, 200).replaceAll('\n', '
')}...' : widget.diet.details.replaceAll('\n', '
'), + data: widget.diet.details.length > 200 + ? '${widget.diet.details.substring(0, 200).replaceAll('\n', '
')}...' + : widget.diet.details.replaceAll('\n', '
'), style: { "*": Style( margin: Margins.zero, @@ -128,6 +131,7 @@ class _MyDietWidgetState extends State { showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время'); } } else if (state.selectedStateIndex == 2) { + GoRouter.of(context).pushNamed(PersonalDietSuggestionScreen.name, extra: widget.diet.id); } else { GoRouter.of(context).pushNamed(CreateDietScreen.name, extra: widget.diet); } diff --git a/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart new file mode 100644 index 00000000..cde49e7e --- /dev/null +++ b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart @@ -0,0 +1,67 @@ +import 'dart:developer'; + +import 'package:eatvio_app/features/diets/repositories/diet_repository.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/repository/personal_diet_suggestion_repository.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class PersonalDietSuggestionCubit extends Cubit { + final DietRepository dietRepository; + final PersonalDietSuggestionRepository personalDietSuggestionService; + late final int dietId; + PersonalDietSuggestionCubit({required this.dietRepository, required this.personalDietSuggestionService}) : super(PersonalDietSuggestionState()); + + Future setDietName(int dietId) async { + try { + emit(state.copyWith(isLoading: true, error: null)); + final diet = await dietRepository.getDiet(dietId); + emit(state.copyWith(isLoading: false, dietName: diet.name)); + } catch (e, st) { + log(e.toString(), stackTrace: st); + emit(state.copyWith(isLoading: false, error: e.toString())); + } + } + + Future getConsultationWithPersonalDiets(int dietId) async { + try { + this.dietId = dietId; + emit(state.copyWith(isLoading: true, error: null)); + setDietName(dietId); + final consultations = await personalDietSuggestionService.getConsultationWithPersonalDiets(); + final consultationWithDiet = consultations.where((consultation) => consultation.personalDietId != null).toList(); + final consultationWithoutDiet = consultations.where((consultation) => consultation.personalDietId == null).toList(); + emit(state.copyWith( + isLoading: false, + consultationsWithDiet: consultationWithDiet, + consultationsWithoutDiet: consultationWithoutDiet, + )); + } catch (e, st) { + log(e.toString(), stackTrace: st); + emit(state.copyWith(isLoading: false, error: e.toString())); + } + } + + Future attachDietToConsultation({ + required int consultationId, + }) async { + try { + await personalDietSuggestionService.attachPersonalDiet(consultationId: consultationId, dietId: dietId); + return true; + } catch (e, st) { + log(e.toString(), stackTrace: st); + return false; + } + } + + Future reattachDietToConsultation({ + required int consultationId, + }) async { + try { + await personalDietSuggestionService.reattachPersonalDiet(consultationId: consultationId, dietId: dietId); + return true; + } catch (e, st) { + log(e.toString(), stackTrace: st); + return false; + } + } +} diff --git a/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart new file mode 100644 index 00000000..da927703 --- /dev/null +++ b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart @@ -0,0 +1,16 @@ +import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'personal_diet_suggestion_state.freezed.dart'; + +@freezed +abstract class PersonalDietSuggestionState with _$PersonalDietSuggestionState { + factory PersonalDietSuggestionState({ + @Default([]) List consultationsWithDiet, + @Default([]) List consultationsWithoutDiet, + @Default('') String dietName, + @Default(false) bool isLoading, + @Default(null) String? error, + }) = _PersonalDietSuggestionState; + +} \ No newline at end of file diff --git a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart new file mode 100644 index 00000000..0207ed41 --- /dev/null +++ b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart @@ -0,0 +1,58 @@ +import 'package:eatvio_app/core/theme/custom_text_style.dart'; +import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; +import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; +import 'package:eatvio_app/generated/l10n.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class ConsultationWidget extends StatelessWidget { + const ConsultationWidget({super.key, required this.consultationModel}); + final ConsultationModel consultationModel; + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4), + color: appTheme.whiteA700, + ), + child: Column( + children: [ + ListTile( + leading: Container( + decoration: const BoxDecoration( + shape: BoxShape.circle, + ), + child: Image.network(consultationModel.userProfilePhotoUrl), + ), + ), + const SizedBox( + height: 12, + ), + if (consultationModel.personalDietId != null) + CustomOutlinedButton( + text: s.changeDiet, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), + buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.dividerColor)), + onPressed: () async { + context.read().reattachDietToConsultation(consultationId: consultationModel.id); + }, + ) + else + CustomOutlinedButton( + text: s.suggestDiet, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + onPressed: () async { + context.read().attachDietToConsultation(consultationId: consultationModel.id); + }, + ) + ], + ), + ); + } +} diff --git a/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart b/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart new file mode 100644 index 00000000..2db01fb3 --- /dev/null +++ b/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart @@ -0,0 +1,66 @@ +import 'package:eatvio_app/core/locator_service.dart'; +import 'package:eatvio_app/core/theme/custom_text_style.dart'; +import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/widgets/loader.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/presentation/consultation_widget.dart'; +import 'package:eatvio_app/generated/l10n.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class PersonalDietSuggestionScreen extends StatelessWidget { + final int dietId; + const PersonalDietSuggestionScreen({super.key, required this.dietId}); + static const path = '/personal-diet-suggestion'; + static const name = 'personalDietSuggestion'; + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => sl()..getConsultationWithPersonalDiets(dietId), + child: const PersonalDietSuggestionScreenContent(), + ); + } +} + +class PersonalDietSuggestionScreenContent extends StatelessWidget { + const PersonalDietSuggestionScreenContent({super.key}); + @override + Widget build(BuildContext context) { + final s = S.of(context); + return BlocBuilder( + builder: (context, state) { + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: Text( + '${s.dietSuggestion}\n«${state.dietName}»', + style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), + ), + ), + body: state.isLoading + ? const Center(child: Loader()) + : SingleChildScrollView( + child: Column( + children: [ + ...List.generate(state.consultationsWithDiet.length, (index) { + return ConsultationWidget( + consultationModel: state.consultationsWithDiet[index], + ); + }), + const SizedBox( + height: 12, + ), + ...List.generate(state.consultationsWithoutDiet.length, (index) { + return ConsultationWidget( + consultationModel: state.consultationsWithoutDiet[index], + ); + }) + ], + ), + ), + ); + }, + ); + } +} diff --git a/lib/features/personal_diet_suggestion/repository/personal_diet_suggestion_repository.dart b/lib/features/personal_diet_suggestion/repository/personal_diet_suggestion_repository.dart new file mode 100644 index 00000000..23c32436 --- /dev/null +++ b/lib/features/personal_diet_suggestion/repository/personal_diet_suggestion_repository.dart @@ -0,0 +1,32 @@ +import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; +import 'package:eatvio_app/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart'; + +class PersonalDietSuggestionRepository { + final PersonalDietSuggestionService personalDietSuggestionService; + + PersonalDietSuggestionRepository({required this.personalDietSuggestionService}); + + Future> getConsultationWithPersonalDiets() async{ + try { + return (await personalDietSuggestionService.getConsultationWithPersonalDiets()).data; + } catch (e) { + rethrow; + } + } + + Future attachPersonalDiet({required int consultationId, required int dietId}) { + try { + return personalDietSuggestionService.attachPersonalDiet(consultationId: consultationId, dietId: dietId); + } catch (e) { + rethrow; + } + } + + Future reattachPersonalDiet({required int consultationId, required int dietId}) { + try { + return personalDietSuggestionService.reattachPersonalDiet(consultationId: consultationId, dietId: dietId); + } catch (e) { + rethrow; + } + } +} diff --git a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart new file mode 100644 index 00000000..584611e2 --- /dev/null +++ b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart @@ -0,0 +1,33 @@ +import 'package:dio/dio.dart'; +import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; + +class PersonalDietSuggestionService { + final Dio dio; + PersonalDietSuggestionService(this.dio); + + Future getConsultationWithPersonalDiets() async { + try { + final response = + await dio.get('/api/consultations', queryParameters: {'filters[plan][has_personal_diet][\$personal_diet]': '1', 'sort[]': 'start_date:desc'}); + return ConsultationPaginationModel.fromJson(response.data); + } catch (e) { + rethrow; + } + } + + Future attachPersonalDiet({required int consultationId, required int dietId}) async { + try { + await dio.post('api/chosen_plans/$consultationId/attach_diet', data: {'diet_id': dietId}); + } catch (e) { + rethrow; + } + } + + Future reattachPersonalDiet({required int consultationId, required int dietId}) async { + try { + await dio.post('api/chosen_plans/$consultationId/re_attach_diet', data: {'diet_id': dietId}); + } catch (e) { + rethrow; + } + } +} diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index b7ec0ca8..27ba4cb3 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -129,6 +129,7 @@ class MessageLookup extends MessageLookupByLibrary { "Если вы любите мучные продукты, но хотите придерживаться диеты, вам подходит диета с добавленим мучных блюд на основе цельнозерновых вариантов. В них больше сложных углеводов и клетчатки, что способствует длительному чувству сытости и поддерживает здоровье пищеварительной системы.", ), "carbohydrates": MessageLookupByLibrary.simpleMessage("Углеводы"), + "changeDiet": MessageLookupByLibrary.simpleMessage("Заменить диету"), "chargeApproved": MessageLookupByLibrary.simpleMessage("Выплата одобрена"), "chargeCollectionFailed": MessageLookupByLibrary.simpleMessage( "Не удалось оформить выплату", @@ -262,6 +263,7 @@ class MessageLookup extends MessageLookupByLibrary { "deleted": MessageLookupByLibrary.simpleMessage("Удалена"), "diary": MessageLookupByLibrary.simpleMessage("Дневник"), "diet": MessageLookupByLibrary.simpleMessage("Диета"), + "dietSuggestion": MessageLookupByLibrary.simpleMessage("Предложение диеты"), "diet_author": MessageLookupByLibrary.simpleMessage("Автор диеты"), "diet_has_been_sent_to_draft": MessageLookupByLibrary.simpleMessage( "снята с публикации и перенесена в черновик", @@ -677,6 +679,7 @@ class MessageLookup extends MessageLookupByLibrary { "successfully_published": MessageLookupByLibrary.simpleMessage( "успешно опубликован", ), + "suggestDiet": MessageLookupByLibrary.simpleMessage("Предложить диету"), "suicide": MessageLookupByLibrary.simpleMessage("Склонение к самоубийству"), "takes_pills": MessageLookupByLibrary.simpleMessage("Принимает лекарства"), "tap_on_link_to_pay": MessageLookupByLibrary.simpleMessage( diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 97792fb3..a705d918 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -3395,16 +3395,6 @@ class S { ); } - /// `Составление индивидуальной диеты` - String get personalDietCreating { - return Intl.message( - 'Составление индивидуальной диеты', - name: 'personalDietCreating', - desc: '', - args: [], - ); - } - /// `Скопировать` String get copy { return Intl.message('Скопировать', name: 'copy', desc: '', args: []); @@ -3424,6 +3414,46 @@ class S { args: [], ); } + + /// `Составление индивидуальной диеты` + String get personalDietCreating { + return Intl.message( + 'Составление индивидуальной диеты', + name: 'personalDietCreating', + desc: '', + args: [], + ); + } + + /// `Предложение диеты` + String get dietSuggestion { + return Intl.message( + 'Предложение диеты', + name: 'dietSuggestion', + desc: '', + args: [], + ); + } + + /// `Предложить диету` + String get suggestDiet { + return Intl.message( + 'Предложить диету', + name: 'suggestDiet', + desc: '', + args: [], + ); + } + + /// `Заменить диету` + String get changeDiet { + return Intl.message( + 'Заменить диету', + name: 'changeDiet', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index f88e36a0..d7d81139 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -407,6 +407,9 @@ "reply": "Ответить", "deleteComment": "Удалить комментарий" , - "personalDietCreating": "Составление индивидуальной диеты" + "personalDietCreating": "Составление индивидуальной диеты", + "dietSuggestion": "Предложение диеты", + "suggestDiet": "Предложить диету", + "changeDiet": "Заменить диету" } From a07d085ba7c3756b21c3f40a8f97e2db6d0148e0 Mon Sep 17 00:00:00 2001 From: Username1548 Date: Mon, 14 Jul 2025 20:24:40 +0700 Subject: [PATCH 3/7] feat(personalDiets): preapared chats for consultations with personal diets --- .../chat/presentation/pages/chat_screen.dart | 41 ++-- .../widgets/chose_plan_date_widget.dart | 188 ++++++++++++------ .../widgets/notification_banner.dart | 25 ++- .../presentation/widgets/calendar_widget.dart | 13 +- .../presentation/consultation_widget.dart | 3 +- .../personal_diet_suggestion_service.dart | 2 +- .../plans/enums/chosen_plan_state_enum.dart | 6 +- lib/generated/intl/messages_en.dart | 13 ++ lib/generated/l10n.dart | 40 ++++ lib/l10n/intl_en.arb | 6 +- 10 files changed, 251 insertions(+), 86 deletions(-) diff --git a/lib/features/chat/presentation/pages/chat_screen.dart b/lib/features/chat/presentation/pages/chat_screen.dart index 55f74d70..e3a042a7 100644 --- a/lib/features/chat/presentation/pages/chat_screen.dart +++ b/lib/features/chat/presentation/pages/chat_screen.dart @@ -110,25 +110,6 @@ class _ChatScreenState extends State { ChosenPlanStateEnum.statePendingPayment, ChosenPlanStateEnum.stateInCoordination, ].contains(chosenPlan?.chosenPlanState); - - final showAboutOrderButton = - state.chatRoom.chosenPlan != null && state.chatRoom.chosenPlan!.chosenPlanState != ChosenPlanStateEnum.stateCanceledByTheInitiator; - BannerType? bannerType; - if (chosenPlan == null || chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateCanceledByTheInitiator) { - bannerType = null; - } else if (amIConsultant && !state.hasCard) { - bannerType = BannerType.card; - } else if (amIConsultant && chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateInCoordination) { - bannerType = BannerType.date; - } else if (!amIConsultant && - (chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateStartDateHasBeenSet || chosenPlan.chosenPlanState == ChosenPlanStateEnum.statePendingPayment)) { - bannerType = BannerType.payment; - } else if (chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateDone && amIConsultant) { - bannerType = BannerType.collectCharge; - } else if (chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateLastDayFinished && !amIConsultant) { - bannerType = BannerType.finishPlan; - } - PacketOptions? chosenOption; if (chosenPlan?.optionType == 'options1') { chosenOption = chosenPlan?.plan.packet1Options; @@ -137,6 +118,27 @@ class _ChatScreenState extends State { } else if (chosenPlan?.optionType == 'options3') { chosenOption = chosenPlan?.plan.packet3Options; } + + final showAboutOrderButton = + state.chatRoom.chosenPlan != null && state.chatRoom.chosenPlan!.chosenPlanState != ChosenPlanStateEnum.stateCanceledByTheInitiator; + BannerType? bannerType; + if (chosenPlan == null || chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateCanceledByTheInitiator) { + bannerType = null; + } else if (amIConsultant && !state.hasCard && chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateInCoordination) { + bannerType = BannerType.card; + } else if (amIConsultant && chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateInCoordination) { + bannerType = BannerType.date; + } else if (!amIConsultant && + (chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateStartDateHasBeenSet || chosenPlan.chosenPlanState == ChosenPlanStateEnum.statePendingPayment)) { + bannerType = BannerType.payment; + } else if (chosenOption?.hasPersonalDiet == true && amIConsultant) { + bannerType = BannerType.setPersonalDiet; + } else if (chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateDone && amIConsultant) { + bannerType = BannerType.collectCharge; + } else if (chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateLastDayFinished && !amIConsultant) { + bannerType = BannerType.finishPlan; + } + return Scaffold( resizeToAvoidBottomInset: true, appBar: AppBar( @@ -330,6 +332,7 @@ class _ChatScreenState extends State { chosenPlanId: chosenPlan?.id, planName: chosenPlan?.plan.name, planPrice: chosenOption?.price.toDouble(), + hasPersonalDiet: chosenOption?.hasPersonalDiet ?? false, ), ), ], diff --git a/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart b/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart index 5ec4e370..1b138f93 100644 --- a/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart +++ b/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart @@ -9,17 +9,28 @@ import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_portal/flutter_portal.dart'; +import 'package:flutter_svg/flutter_svg.dart'; class ChosePlanDateWidget extends StatefulWidget { - const ChosePlanDateWidget({super.key, required this.chatCubit}); + const ChosePlanDateWidget({super.key, required this.chatCubit, required this.hasPersonalDiet}); final ChatRoomCubit chatCubit; - + final bool hasPersonalDiet; @override State createState() => _ChosePlanDateWidget(); } class _ChosePlanDateWidget extends State { - final startDate = [DateTime.now()]; + late final List startDate; + bool visible = false; + @override + void initState() { + super.initState(); + if (widget.hasPersonalDiet) { + startDate = [DateTime.now().add(const Duration(days: 2))]; + } + } + @override Widget build(BuildContext context) { final s = S.of(context); @@ -27,64 +38,129 @@ class _ChosePlanDateWidget extends State { if (widget.chatCubit.state is ChatRoomStateLoaded) { planName = (widget.chatCubit.state as ChatRoomStateLoaded).chatRoom.chosenPlan?.plan.name; } - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox(height: 4), - const BottomSheetHandlerBar(), - const SizedBox(height: 12), - Text( - planName ?? '', - style: TextStyles.headingXLSemibold.copyWith( - color: appTheme.black, + return GestureDetector( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox(height: 4), + const BottomSheetHandlerBar(), + const SizedBox(height: 12), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + planName ?? '', + style: TextStyles.headingXLSemibold.copyWith( + color: appTheme.black, + ), + ), + if (widget.hasPersonalDiet) ...[ + const SizedBox( + width: 8, + ), + PortalTarget( + closeDuration: const Duration(milliseconds: 20), + anchor: const Aligned( + shiftToWithinBound: AxisFlag(x: true, y: true), + follower: Alignment.topRight, + target: Alignment.bottomLeft, + ), + portalFollower: Padding( + padding: const EdgeInsetsGeometry.symmetric(horizontal: 20), + child: Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + color: visible ? appTheme.whiteA700 : Colors.transparent, + boxShadow: visible + ? [ + BoxShadow( + color: appTheme.black900.withValues(alpha: 0.15), + blurRadius: 4, + offset: const Offset(0, 4), + ), + ] + : null, + ), + child: AnimatedDefaultTextStyle( + style: TextStyles.textMMediumAuto.copyWith( + color: visible ? appTheme.black : Colors.transparent, + ), + duration: const Duration(milliseconds: 300), + child: Text( + s.chosenPlanStartDateDescr, + ), + ), + ), + ), + child: GestureDetector( + onTap: () { + setState(() { + visible = !visible; + }); + }, + child: SvgPicture.asset( + 'assets/icons/question_mark.svg', + width: 22, + height: 22, + colorFilter: ColorFilter.mode( + appTheme.blueA400, + BlendMode.srcIn, + ), + ), + ), + ) + ] + ], ), - ), - const SizedBox(height: 12), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 25.0), - child: Text( - s.chose_plan_start_date_2, - textAlign: TextAlign.center, - style: TextStyles.textMMedium.copyWith( - color: appTheme.black, + const SizedBox(height: 12), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 25.0), + child: Text( + s.chose_plan_start_date_2, + textAlign: TextAlign.center, + style: TextStyles.textMMedium.copyWith( + color: appTheme.black, + ), ), ), - ), - const SizedBox(height: 12), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 16.0), - child: CustomDivider(), - ), - CalendarWidget( - startDate: startDate, - ), - Padding( - padding: const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 28), - child: CustomOutlinedButton( - onPressed: () async { - final result = await widget.chatCubit.choseStartPlanDate(startDate[0]); - if (result) { - showSuccessToast('Дата установлена'); - if (!context.mounted) return; - Navigator.pop(context); - } else { - showErrorToast('Не удалось установить дату'); - if (!context.mounted) return; - Navigator.pop(context); - } - }, - height: 60, - text: s.confirm, - buttonTextStyle: TextStyles.textLSemibold.copyWith( - color: appTheme.whiteA700, - ), - buttonStyle: ButtonStyle( - backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), - side: const WidgetStatePropertyAll(BorderSide.none), + const SizedBox(height: 12), + const Padding( + padding: EdgeInsets.symmetric(horizontal: 16.0), + child: CustomDivider(), + ), + CalendarWidget( + startDate: startDate, + ), + Padding( + padding: const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 28), + child: CustomOutlinedButton( + onPressed: () async { + final result = await widget.chatCubit.choseStartPlanDate(startDate[0]); + if (result) { + showSuccessToast('Дата установлена'); + if (!context.mounted) return; + Navigator.pop(context); + } else { + showErrorToast('Не удалось установить дату'); + if (!context.mounted) return; + Navigator.pop(context); + } + }, + height: 60, + text: s.confirm, + buttonTextStyle: TextStyles.textLSemibold.copyWith( + color: appTheme.whiteA700, + ), + buttonStyle: ButtonStyle( + backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), + side: const WidgetStatePropertyAll(BorderSide.none), + ), ), ), - ), - ], + ], + ), ); } } diff --git a/lib/features/chat/presentation/widgets/notification_banner.dart b/lib/features/chat/presentation/widgets/notification_banner.dart index 8828863f..3a8203f9 100644 --- a/lib/features/chat/presentation/widgets/notification_banner.dart +++ b/lib/features/chat/presentation/widgets/notification_banner.dart @@ -9,6 +9,7 @@ import 'package:eatvio_app/features/chat/presentation/pages/payment_screen.dart' import 'package:eatvio_app/features/chat/presentation/widgets/chose_plan_date_widget.dart'; import 'package:eatvio_app/features/chat/presentation/widgets/complete_plan_bottom_sheet.dart'; import 'package:eatvio_app/features/chat/presentation/widgets/plan_complain_bottom_sheet.dart'; +import 'package:eatvio_app/features/my_diets/presentation/my_diets_screen.dart'; import 'package:eatvio_app/features/my_finance/presentation/pages/card_settings.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; @@ -17,12 +18,12 @@ import 'package:flutter_svg/svg.dart'; import 'package:go_router/go_router.dart'; class NotificationBanner extends StatefulWidget { - const NotificationBanner({super.key, required this.bannerType, this.planPrice, this.planName, this.chosenPlanId}); + const NotificationBanner({super.key, required this.bannerType, this.planPrice, this.planName, this.chosenPlanId, this.hasPersonalDiet = false}); final BannerType bannerType; final double? planPrice; final String? planName; final int? chosenPlanId; - + final bool hasPersonalDiet; @override State createState() => _NotificationBannerState(); } @@ -68,7 +69,8 @@ class _NotificationBannerState extends State { BannerType.date => [ SizedBox( width: size.width * 0.6, - child: Text(s.choose_plan_start_date, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), + child: Text(widget.hasPersonalDiet == true ? s.choose_plan_start_date_with_personal_diet : s.choose_plan_start_date, + style: TextStyles.textMMedium.copyWith(color: appTheme.black)), ), const SizedBox(height: 12), GestureDetector( @@ -78,6 +80,7 @@ class _NotificationBannerState extends State { context: context, builder: (context) => ChosePlanDateWidget( chatCubit: cubit, + hasPersonalDiet: widget.hasPersonalDiet, ), ); }, @@ -155,6 +158,20 @@ class _NotificationBannerState extends State { ), const SizedBox(height: 8), ], + BannerType.setPersonalDiet => [ + SizedBox( + width: size.width * 0.6, + child: Text(s.createPersonalDiet, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), + ), + const SizedBox(height: 12), + GestureDetector( + onTap: () { + GoRouter.of(context).pushNamed(MyDietsScreen.name); + }, + child: Text(s.goToMyDiets, style: TextStyles.textLSemibold.copyWith(color: appTheme.blueA400)), + ), + const SizedBox(height: 16), + ], }, ), ), @@ -242,4 +259,4 @@ class _StarIcon extends StatelessWidget { } } -enum BannerType { date, card, payment, collectCharge, finishPlan } +enum BannerType { date, card, payment, collectCharge, finishPlan, setPersonalDiet } diff --git a/lib/features/diets/presentation/widgets/calendar_widget.dart b/lib/features/diets/presentation/widgets/calendar_widget.dart index 316913b3..1daace4b 100644 --- a/lib/features/diets/presentation/widgets/calendar_widget.dart +++ b/lib/features/diets/presentation/widgets/calendar_widget.dart @@ -13,8 +13,15 @@ class CalendarWidget extends StatefulWidget { class _CalendarWidgetState extends State { CalendarFormat _calendarFormat = CalendarFormat.week; - DateTime _focusedDay = DateTime.now(); - DateTime? _selectedDay = DateTime.now(); + late DateTime _focusedDay; + DateTime? _selectedDay; + + @override + void initState() { + super.initState(); + _selectedDay = widget.startDate.isEmpty ? DateTime.now() : widget.startDate[0]; + _focusedDay = widget.startDate.isEmpty ? DateTime.now() : widget.startDate[0]; + } @override Widget build(BuildContext context) { return Column( @@ -23,7 +30,7 @@ class _CalendarWidgetState extends State { Padding( padding: const EdgeInsets.only(top: 5), child: TableCalendar( - firstDay: DateTime.now(), + firstDay: widget.startDate.isEmpty ? DateTime.now() : widget.startDate[0], lastDay: DateTime.utc(2030, 3, 14), locale: 'ru_RU', startingDayOfWeek: StartingDayOfWeek.monday, diff --git a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart index 0207ed41..77042d13 100644 --- a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart +++ b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/core/const.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; @@ -25,7 +26,7 @@ class ConsultationWidget extends StatelessWidget { decoration: const BoxDecoration( shape: BoxShape.circle, ), - child: Image.network(consultationModel.userProfilePhotoUrl), + child: Image.network('$baseUrl/${consultationModel.userProfilePhotoUrl}'), ), ), const SizedBox( diff --git a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart index 584611e2..2325bb72 100644 --- a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart +++ b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart @@ -8,7 +8,7 @@ class PersonalDietSuggestionService { Future getConsultationWithPersonalDiets() async { try { final response = - await dio.get('/api/consultations', queryParameters: {'filters[plan][has_personal_diet][\$personal_diet]': '1', 'sort[]': 'start_date:desc'}); + await dio.get('/api/consultations', queryParameters: {'filters[plan][has_personal_diet]': '1', 'sort[]': 'start_date:desc'}); return ConsultationPaginationModel.fromJson(response.data); } catch (e) { rethrow; diff --git a/lib/features/plans/enums/chosen_plan_state_enum.dart b/lib/features/plans/enums/chosen_plan_state_enum.dart index 0b768d5f..2f37ec30 100644 --- a/lib/features/plans/enums/chosen_plan_state_enum.dart +++ b/lib/features/plans/enums/chosen_plan_state_enum.dart @@ -27,6 +27,8 @@ enum ChosenPlanStateEnum { stateComplained, @JsonValue('done') stateDone, + @JsonValue('personal_diet_setted') + personalDietSet, @JsonValue('charge_was_collected') stateChargeWasCollected; @@ -40,6 +42,7 @@ enum ChosenPlanStateEnum { ChosenPlanStateEnum.stateLastDayFinished, ChosenPlanStateEnum.stateDone, ChosenPlanStateEnum.stateInProgress, + ChosenPlanStateEnum.personalDietSet, ]; } @@ -64,7 +67,8 @@ enum ChosenPlanStateEnum { ChosenPlanStateEnum.stateLastDayStarted, ChosenPlanStateEnum.stateLastDayFinished, ChosenPlanStateEnum.stateComplained, - ChosenPlanStateEnum.stateDone + ChosenPlanStateEnum.stateDone, + ChosenPlanStateEnum.personalDietSet ]; } } diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 27ba4cb3..96c0a8d0 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -150,6 +150,10 @@ class MessageLookup extends MessageLookupByLibrary { "choose_plan_start_date": MessageLookupByLibrary.simpleMessage( "Выберите дату старта плана питания", ), + "choose_plan_start_date_with_personal_diet": + MessageLookupByLibrary.simpleMessage( + "Выберите дату старта плана питания с учетом составления персональной диеты", + ), "choose_start_diet_date": MessageLookupByLibrary.simpleMessage( "Выберите дату старты диеты. Она отобразиться у Вас в дневнике", ), @@ -157,6 +161,9 @@ class MessageLookup extends MessageLookupByLibrary { "chose_plan_start_date_2": MessageLookupByLibrary.simpleMessage( "Выберите дату старты плана. Она отобразиться в дневнике пользователя", ), + "chosenPlanStartDateDescr": MessageLookupByLibrary.simpleMessage( + "Дату старта плана можно выбрать не ранее, чем через два. Такое ограничение дается на создание персональной диеты", + ), "circumference_empty": MessageLookupByLibrary.simpleMessage( "Все замеры обязательны к заполнению", ), @@ -237,6 +244,9 @@ class MessageLookup extends MessageLookupByLibrary { "Не удалось обновить диету", ), "country": MessageLookupByLibrary.simpleMessage("Страна"), + "createPersonalDiet": MessageLookupByLibrary.simpleMessage( + "Составьте персональную диету", + ), "create_diet": MessageLookupByLibrary.simpleMessage("Создание диеты"), "cunsutation_was_paid_successfully": MessageLookupByLibrary.simpleMessage( "Поздравляем, консультация успешно оплачена", @@ -379,6 +389,9 @@ class MessageLookup extends MessageLookupByLibrary { "from_z_to_a": MessageLookupByLibrary.simpleMessage("Название: Я-А"), "gallery": MessageLookupByLibrary.simpleMessage("Галерея"), "general_info": MessageLookupByLibrary.simpleMessage("Общая информация"), + "goToMyDiets": MessageLookupByLibrary.simpleMessage( + "Перейти к моим диетам", + ), "go_to_diary": MessageLookupByLibrary.simpleMessage("Перейти в дневник"), "gr": MessageLookupByLibrary.simpleMessage("гр"), "grams": MessageLookupByLibrary.simpleMessage("гр"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index a705d918..29dc55a3 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -3454,6 +3454,46 @@ class S { args: [], ); } + + /// `Выберите дату старта плана питания с учетом составления персональной диеты` + String get choose_plan_start_date_with_personal_diet { + return Intl.message( + 'Выберите дату старта плана питания с учетом составления персональной диеты', + name: 'choose_plan_start_date_with_personal_diet', + desc: '', + args: [], + ); + } + + /// `Дату старта плана можно выбрать не ранее, чем через два. Такое ограничение дается на создание персональной диеты` + String get chosenPlanStartDateDescr { + return Intl.message( + 'Дату старта плана можно выбрать не ранее, чем через два. Такое ограничение дается на создание персональной диеты', + name: 'chosenPlanStartDateDescr', + desc: '', + args: [], + ); + } + + /// `Составьте персональную диету` + String get createPersonalDiet { + return Intl.message( + 'Составьте персональную диету', + name: 'createPersonalDiet', + desc: '', + args: [], + ); + } + + /// `Перейти к моим диетам` + String get goToMyDiets { + return Intl.message( + 'Перейти к моим диетам', + name: 'goToMyDiets', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index d7d81139..21000e10 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -410,6 +410,10 @@ "personalDietCreating": "Составление индивидуальной диеты", "dietSuggestion": "Предложение диеты", "suggestDiet": "Предложить диету", - "changeDiet": "Заменить диету" + "changeDiet": "Заменить диету", + "choose_plan_start_date_with_personal_diet": "Выберите дату старта плана питания с учетом составления персональной диеты", + "chosenPlanStartDateDescr": "Дату старта плана можно выбрать не ранее, чем через два. Такое ограничение дается на создание персональной диеты", + "createPersonalDiet": "Составьте персональную диету", + "goToMyDiets": "Перейти к моим диетам" } From 7e64b24a8c9f41f2b10043ec29c20b1df4e7a90c Mon Sep 17 00:00:00 2001 From: Username1548 Date: Tue, 15 Jul 2025 21:49:47 +0700 Subject: [PATCH 4/7] added layout for suggestions page --- .../widgets/chose_plan_date_widget.dart | 2 +- .../presentation/consultation_widget.dart | 320 +++++++++++++++++- .../personal_diet_suggestion_screen.dart | 3 + .../personal_diet_suggestion_service.dart | 7 +- 4 files changed, 318 insertions(+), 14 deletions(-) diff --git a/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart b/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart index 1b138f93..2744ba74 100644 --- a/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart +++ b/lib/features/chat/presentation/widgets/chose_plan_date_widget.dart @@ -67,7 +67,7 @@ class _ChosePlanDateWidget extends State { target: Alignment.bottomLeft, ), portalFollower: Padding( - padding: const EdgeInsetsGeometry.symmetric(horizontal: 20), + padding: const EdgeInsets.symmetric(horizontal: 20), child: Container( padding: const EdgeInsets.all(10), decoration: BoxDecoration( diff --git a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart index 77042d13..3f47db11 100644 --- a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart +++ b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart @@ -1,34 +1,86 @@ +import 'package:eatvio_app/core/app_router.dart'; import 'package:eatvio_app/core/const.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart'; +import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart'; import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:go_router/go_router.dart'; class ConsultationWidget extends StatelessWidget { - const ConsultationWidget({super.key, required this.consultationModel}); + const ConsultationWidget({super.key, required this.consultationModel, required this.dietName}); final ConsultationModel consultationModel; + final String dietName; @override Widget build(BuildContext context) { final s = S.of(context); return Container( + padding: const EdgeInsets.all(16), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(4), + borderRadius: BorderRadius.circular(12), color: appTheme.whiteA700, ), child: Column( children: [ - ListTile( - leading: Container( - decoration: const BoxDecoration( - shape: BoxShape.circle, - ), - child: Image.network('$baseUrl/${consultationModel.userProfilePhotoUrl}'), + if (consultationModel.personalDietId == null) + Row( + children: [ + CircleAvatar( + radius: 30, + backgroundImage: NetworkImage(baseUrl + consultationModel.userProfilePhotoUrl), + ), + const SizedBox(width: 12), + Column( + mainAxisSize: MainAxisSize.min, + spacing: 4, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + consultationModel.userName, + style: TextStyles.textLSemibold.copyWith(color: appTheme.black), + ), + Text( + consultationModel.planTitle, + style: TextStyles.textMMedium.copyWith(color: const Color(0xFF88949F)), + ), + Text( + 'Старт: ${consultationModel.userName}', + style: TextStyles.textMMedium.copyWith(color: const Color(0xFF88949F)), + ), + ], + ) + ], + ) + else + Row( + children: [ + CircleAvatar( + radius: 30, + backgroundImage: NetworkImage(baseUrl + consultationModel.userProfilePhotoUrl), + ), + const SizedBox(width: 12), + Column( + mainAxisSize: MainAxisSize.min, + spacing: 4, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + consultationModel.userName, + style: TextStyles.textLSemibold.copyWith(color: appTheme.black), + ), + Text( + consultationModel.planTitle, + style: TextStyles.textMMedium.copyWith(color: const Color(0xFF88949F)), + ), + ], + ) + ], ), - ), const SizedBox( height: 12, ), @@ -39,7 +91,42 @@ class ConsultationWidget extends StatelessWidget { buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.dividerColor)), onPressed: () async { - context.read().reattachDietToConsultation(consultationId: consultationModel.id); + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: SuggestDietBottomSheet( + userName: consultationModel.userName, + dietName: dietName, + onTap: () async { + final result = await context.read().attachDietToConsultation(consultationId: consultationModel.id); + AppRouter.navigatorKey.currentContext?.pop(); + if (result) { + if (!context.mounted) return; + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: SuggestionSuccessBottomSheet( + userName: consultationModel.userName, + dietName: dietName, + ), + ); + return; + } + if (!context.mounted) return; + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: SuggestionFailureBottomSheet( + userName: consultationModel.userName, + dietName: dietName, + ), + ); + }, + ), + ); }, ) else @@ -49,7 +136,42 @@ class ConsultationWidget extends StatelessWidget { buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), onPressed: () async { - context.read().attachDietToConsultation(consultationId: consultationModel.id); + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: SuggestDietBottomSheet( + userName: consultationModel.userName, + dietName: dietName, + onTap: () async { + AppRouter.navigatorKey.currentContext?.pop(); + final result = await context.read().attachDietToConsultation(consultationId: consultationModel.id); + if (result) { + if (!context.mounted) return; + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: SuggestionSuccessBottomSheet( + userName: consultationModel.userName, + dietName: dietName, + ), + ); + return; + } + if (!context.mounted) return; + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: SuggestionFailureBottomSheet( + userName: consultationModel.userName, + dietName: dietName, + ), + ); + }, + ), + ); }, ) ], @@ -57,3 +179,179 @@ class ConsultationWidget extends StatelessWidget { ); } } + +class SuggestDietBottomSheet extends StatefulWidget { + const SuggestDietBottomSheet({ + super.key, + required this.userName, + required this.dietName, + required this.onTap, + }); + final String userName; + final String dietName; + final Future Function() onTap; + @override + State createState() => _SuggestDietBottomSheet(); +} + +class _SuggestDietBottomSheet extends State { + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox( + height: 8, + ), + const BottomSheetHandlerBar(), + const SizedBox( + height: 20, + ), + Text('Предложение диеты', style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), + const SizedBox( + height: 16, + ), + Text( + 'Предложить пользователю ${widget.userName} «${widget.dietName}»', + style: TextStyles.textSMedium.copyWith(color: appTheme.black), + textAlign: TextAlign.center, + ), + const SizedBox( + height: 8, + ), + CustomOutlinedButton( + text: s.toOffer, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + onPressed: widget.onTap, + ), + const SizedBox( + height: 40, + ), + ], + ), + ); + } +} + +class SuggestionSuccessBottomSheet extends StatefulWidget { + const SuggestionSuccessBottomSheet({ + super.key, + required this.userName, + required this.dietName, + }); + final String userName; + final String dietName; + + @override + State createState() => _SuggestionSuccessBottomSheet(); +} + +class _SuggestionSuccessBottomSheet extends State { + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox( + height: 8, + ), + const BottomSheetHandlerBar(), + const SizedBox( + height: 20, + ), + Text('Предложение диеты', style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), + const SizedBox( + height: 16, + ), + Text( + '«${widget.dietName}» предложена пользователю ${widget.userName}', + style: TextStyles.textSMedium.copyWith(color: appTheme.black), + textAlign: TextAlign.center, + ), + const SizedBox( + height: 8, + ), + CustomOutlinedButton( + text: s.ok, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + onPressed: () async { + AppRouter.navigatorKey.currentContext?.pop(); + }, + ), + const SizedBox( + height: 40, + ), + ], + ), + ); + } +} + +class SuggestionFailureBottomSheet extends StatefulWidget { + const SuggestionFailureBottomSheet({ + super.key, + required this.userName, + required this.dietName, + }); + final String userName; + final String dietName; + + @override + State createState() => _SuggestionFailureBottomSheet(); +} + +class _SuggestionFailureBottomSheet extends State { + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox( + height: 8, + ), + const BottomSheetHandlerBar(), + const SizedBox( + height: 20, + ), + Text('Предложение диеты', style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), + const SizedBox( + height: 16, + ), + Text( + 'Не удалось предложить диету ${widget.dietName} пользователю ${widget.userName}', + style: TextStyles.textSMedium.copyWith(color: appTheme.black), + textAlign: TextAlign.center, + ), + const SizedBox( + height: 8, + ), + CustomOutlinedButton( + text: s.ok, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + onPressed: () async { + AppRouter.navigatorKey.currentContext?.pop(); + }, + ), + const SizedBox( + height: 40, + ), + ], + ), + ); + } +} diff --git a/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart b/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart index 2db01fb3..dad76406 100644 --- a/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart +++ b/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart @@ -31,6 +31,7 @@ class PersonalDietSuggestionScreenContent extends StatelessWidget { return BlocBuilder( builder: (context, state) { return Scaffold( + backgroundColor: appTheme.gray100, appBar: AppBar( centerTitle: true, title: Text( @@ -46,6 +47,7 @@ class PersonalDietSuggestionScreenContent extends StatelessWidget { ...List.generate(state.consultationsWithDiet.length, (index) { return ConsultationWidget( consultationModel: state.consultationsWithDiet[index], + dietName: state.dietName, ); }), const SizedBox( @@ -54,6 +56,7 @@ class PersonalDietSuggestionScreenContent extends StatelessWidget { ...List.generate(state.consultationsWithoutDiet.length, (index) { return ConsultationWidget( consultationModel: state.consultationsWithoutDiet[index], + dietName: state.dietName, ); }) ], diff --git a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart index 2325bb72..3f65005d 100644 --- a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart +++ b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart @@ -7,8 +7,11 @@ class PersonalDietSuggestionService { Future getConsultationWithPersonalDiets() async { try { - final response = - await dio.get('/api/consultations', queryParameters: {'filters[plan][has_personal_diet]': '1', 'sort[]': 'start_date:desc'}); + final response = await dio.get('/api/consultations', queryParameters: { + 'filters[plan][has_personal_diet][\$personal_diet]': '1', + 'filters[last_state][\$notIn][]': ['done', 'charge_was_collected', 'complained', 'last_day_finished', 'canceled_by_the_initiator', 'inited'], + 'sort[]': 'start_date:desc', + }); return ConsultationPaginationModel.fromJson(response.data); } catch (e) { rethrow; From 19787f459e054b3956868c9850f6b685c88b1954 Mon Sep 17 00:00:00 2001 From: Username1548 Date: Wed, 16 Jul 2025 17:03:46 +0700 Subject: [PATCH 5/7] feat(personalDiet): fixed wrong path for attach diet method --- .../services/personal_diet_suggestion_service.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart index 3f65005d..0a10c26e 100644 --- a/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart +++ b/lib/features/personal_diet_suggestion/services/personal_diet_suggestion_service.dart @@ -20,7 +20,7 @@ class PersonalDietSuggestionService { Future attachPersonalDiet({required int consultationId, required int dietId}) async { try { - await dio.post('api/chosen_plans/$consultationId/attach_diet', data: {'diet_id': dietId}); + await dio.post('/api/chosen_plans/$consultationId/attach_diet', data: {'diet_id': dietId}); } catch (e) { rethrow; } @@ -28,7 +28,7 @@ class PersonalDietSuggestionService { Future reattachPersonalDiet({required int consultationId, required int dietId}) async { try { - await dio.post('api/chosen_plans/$consultationId/re_attach_diet', data: {'diet_id': dietId}); + await dio.post('/api/chosen_plans/$consultationId/re_attach_diet', data: {'diet_id': dietId}); } catch (e) { rethrow; } From 46841fb502da3f1e2ee665e7b813662cc134a8eb Mon Sep 17 00:00:00 2001 From: misha Date: Thu, 2 Oct 2025 13:49:58 +0300 Subject: [PATCH 6/7] feat(personalDiets): fixed PlanState widget in order to show personal diet state --- ...otlin-compiler-10039299475187077818.salive | 0 .../presentation/info_by_order_screen.dart | 104 +++++------------- .../presentation/widgets/plan_state.dart | 100 +++++++++-------- lib/generated/intl/messages_en.dart | 3 + lib/generated/l10n.dart | 17 ++- lib/l10n/intl_en.arb | 3 +- 6 files changed, 104 insertions(+), 123 deletions(-) delete mode 100644 android/.kotlin/sessions/kotlin-compiler-10039299475187077818.salive diff --git a/android/.kotlin/sessions/kotlin-compiler-10039299475187077818.salive b/android/.kotlin/sessions/kotlin-compiler-10039299475187077818.salive deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/order_info/presentation/info_by_order_screen.dart b/lib/features/order_info/presentation/info_by_order_screen.dart index 0aa5e6e7..b3627ac2 100644 --- a/lib/features/order_info/presentation/info_by_order_screen.dart +++ b/lib/features/order_info/presentation/info_by_order_screen.dart @@ -31,10 +31,7 @@ class InfoByOrderScreen extends StatelessWidget { Widget build(BuildContext context) { return BlocProvider( create: (context) => sl()..getChosenPlan(planId), - child: InfoByOrderScreenContent( - successfulPayment: successfulPayment, - planId: planId, - ), + child: InfoByOrderScreenContent(successfulPayment: successfulPayment, planId: planId), ); } } @@ -42,11 +39,7 @@ class InfoByOrderScreen extends StatelessWidget { class InfoByOrderScreenContent extends StatefulWidget { static const name = 'infoByOrderScreen'; static const path = '/info-by-order-screen'; - const InfoByOrderScreenContent({ - super.key, - required this.planId, - required this.successfulPayment, - }); + const InfoByOrderScreenContent({super.key, required this.planId, required this.successfulPayment}); final int planId; final bool? successfulPayment; @override @@ -64,39 +57,30 @@ class _InfoByOrderScreenContentState extends State { if (state.isLoading) { return Scaffold( appBar: AppBar( - title: Text( - s.infoAboutOrder, - style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), - ), + title: Text(s.infoAboutOrder, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), leading: IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - GoRouter.of(context).pop(); - }), - ), - body: const Center( - child: Loader(), + icon: const Icon(Icons.arrow_back), + onPressed: () { + GoRouter.of(context).pop(); + }, + ), ), + body: const Center(child: Loader()), ); } if (plan == null) { return Scaffold( appBar: AppBar( - title: Text( - s.infoAboutOrder, - style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), - ), + title: Text(s.infoAboutOrder, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), leading: IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - GoRouter.of(context).pop(); - }), + icon: const Icon(Icons.arrow_back), + onPressed: () { + GoRouter.of(context).pop(); + }, + ), ), body: Center( - child: Text( - s.sorry_we_did_not_find_the_plan, - style: TextStyles.textSSemibold.copyWith(color: appTheme.black), - ), + child: Text(s.sorry_we_did_not_find_the_plan, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)), ), ); } @@ -122,31 +106,19 @@ class _InfoByOrderScreenContentState extends State { return Scaffold( backgroundColor: appTheme.gray100, appBar: AppBar( - title: Text( - s.infoAboutOrder, - style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), - ), + title: Text(s.infoAboutOrder, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), leading: IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - GoRouter.of(context).pop(); - }), + icon: const Icon(Icons.arrow_back), + onPressed: () { + GoRouter.of(context).pop(); + }, + ), ), body: SingleChildScrollView( child: Column( children: [ - if (plan.chosenPlanState == ChosenPlanStateEnum.stateDone) ...[ - CollectChargeBanner( - chosenPlan: plan, - price: chosenOption?.price ?? 0, - ) - ], - if (widget.successfulPayment != null) ...[ - const SizedBox(height: 8), - PaymentBanner( - successfulPayment: widget.successfulPayment ?? false, - ), - ], + if (plan.chosenPlanState == ChosenPlanStateEnum.stateDone) ...[CollectChargeBanner(chosenPlan: plan, price: chosenOption?.price ?? 0)], + if (widget.successfulPayment != null) ...[const SizedBox(height: 8), PaymentBanner(successfulPayment: widget.successfulPayment ?? false)], const SizedBox(height: 8), AuthorCard( author: plan.plan.author, @@ -155,26 +127,13 @@ class _InfoByOrderScreenContentState extends State { backgroundColor: appTheme.whiteA700, ), const SizedBox(height: 8), - PlanProps( - planDuration: plan.plan.duration, - planPrice: chosenOption?.price.toDouble() ?? 0, - planStatus: planStatus), + PlanProps(planDuration: plan.plan.duration, planPrice: chosenOption?.price.toDouble() ?? 0, planStatus: planStatus), const SizedBox(height: 8), - PlanInfo( - title: plan.plan.name, - description: plan.plan.details, - imagePath: plan.plan.image, - ), + PlanInfo(title: plan.plan.name, description: plan.plan.details, imagePath: plan.plan.image), const SizedBox(height: 8), - OptionWidget( - option: chosenOption, - disableDuration: true, - duration: plan.plan.duration, - ), + OptionWidget(option: chosenOption, disableDuration: true, duration: plan.plan.duration), const SizedBox(height: 8), - PlanState( - state: plan.chosenPlanState, - ), + PlanState(state: plan.chosenPlanState, hasPersonalDiet: chosenOption?.hasPersonalDiet ?? false,), const SizedBox(height: 20), if (widget.successfulPayment == null) CustomOutlinedButton( @@ -185,13 +144,10 @@ class _InfoByOrderScreenContentState extends State { onPressed: () async { showModalBottomSheet( context: context, - builder: (context) => CancelPlanBottomSheet( - enableForm: plan.chosenPlanState.isStateAfterPaidState(), - planId: plan.id, - ), + builder: (context) => CancelPlanBottomSheet(enableForm: plan.chosenPlanState.isStateAfterPaidState(), planId: plan.id), ); }, - ) + ), ], ), ), diff --git a/lib/features/order_info/presentation/widgets/plan_state.dart b/lib/features/order_info/presentation/widgets/plan_state.dart index c5c7c72a..f65b82bb 100644 --- a/lib/features/order_info/presentation/widgets/plan_state.dart +++ b/lib/features/order_info/presentation/widgets/plan_state.dart @@ -5,42 +5,65 @@ import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; -class PlanState extends StatelessWidget { - PlanState({super.key, required this.state}); +class PlanState extends StatefulWidget { + const PlanState({super.key, required this.state, required this.hasPersonalDiet}); final ChosenPlanStateEnum state; - final List> states = [ - [ - ChosenPlanStateEnum.stateInited, - ChosenPlanStateEnum.stateInCoordination, - ], - [ - ChosenPlanStateEnum.stateStartDateHasBeenSet, - ChosenPlanStateEnum.statePendingPayment, - ], - [ - ChosenPlanStateEnum.statePaid, - ], - [ - ChosenPlanStateEnum.stateStarted, - ChosenPlanStateEnum.stateInProgress, - ChosenPlanStateEnum.stateLastDayStarted, - ChosenPlanStateEnum.stateLastDayFinished, - ], - [ - ChosenPlanStateEnum.stateComplained, - ChosenPlanStateEnum.stateDone, - ChosenPlanStateEnum.stateChargeWasCollected, - ] - ]; + final bool hasPersonalDiet; + + @override + State createState() => _PlanStateState(); +} + +class _PlanStateState extends State { + late final List> states; + + @override + void initState() { + super.initState(); + if (widget.hasPersonalDiet) { + states = [ + [ChosenPlanStateEnum.stateInited, ChosenPlanStateEnum.stateInCoordination], + [ChosenPlanStateEnum.stateStartDateHasBeenSet, ChosenPlanStateEnum.statePendingPayment], + [ChosenPlanStateEnum.statePaid], + [ChosenPlanStateEnum.personalDietSet], + [ + ChosenPlanStateEnum.stateStarted, + ChosenPlanStateEnum.stateInProgress, + ChosenPlanStateEnum.stateLastDayStarted, + ChosenPlanStateEnum.stateLastDayFinished, + ], + [ChosenPlanStateEnum.stateComplained, ChosenPlanStateEnum.stateDone, ChosenPlanStateEnum.stateChargeWasCollected], + ]; + } else { + states = [ + [ChosenPlanStateEnum.stateInited, ChosenPlanStateEnum.stateInCoordination], + [ChosenPlanStateEnum.stateStartDateHasBeenSet, ChosenPlanStateEnum.statePendingPayment], + [ChosenPlanStateEnum.statePaid], + [ + ChosenPlanStateEnum.stateStarted, + ChosenPlanStateEnum.stateInProgress, + ChosenPlanStateEnum.stateLastDayStarted, + ChosenPlanStateEnum.stateLastDayFinished, + ], + [ChosenPlanStateEnum.stateComplained, ChosenPlanStateEnum.stateDone, ChosenPlanStateEnum.stateChargeWasCollected], + ]; + } + } + @override Widget build(BuildContext context) { final s = S.of(context); - final titles = [s.order_created, s.startDateHasBeenSet, s.order_paid, s.in_progress, s.done]; + final List titles; + if (widget.hasPersonalDiet) { + titles = [s.order_created, s.startDateHasBeenSet, s.order_paid, s.personal_diet_set, s.in_progress, s.done]; + } else { + titles = [s.order_created, s.startDateHasBeenSet, s.order_paid, s.in_progress, s.done]; + } return MainBackgroundBouble( padding: const EdgeInsets.all(16), child: Column( children: List.generate(states.length, (index) { - final color = index <= states.indexWhere((element) => element.contains(state)) ? appTheme.greenA700 : appTheme.lightGray00; + final color = index <= states.indexWhere((element) => element.contains(widget.state)) ? appTheme.greenA700 : appTheme.lightGray00; final text = titles[index]; return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -51,29 +74,16 @@ class PlanState extends StatelessWidget { width: 24, height: 24, decoration: BoxDecoration(shape: BoxShape.circle, color: color), - child: Center( - child: Icon( - Icons.check, - color: appTheme.whiteA700, - size: 14, - ), - ), + child: Center(child: Icon(Icons.check, color: appTheme.whiteA700, size: 14)), ), const SizedBox(width: 12), - Text( - text, - style: TextStyles.textMMedium.copyWith(color: appTheme.black), - ), + Text(text, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), ], ), Padding( padding: const EdgeInsets.only(left: 12), - child: Container( - height: 12, - width: 1, - color: color, - ), - ) + child: Container(height: 12, width: 1, color: color), + ), ], ); }), diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index f44df4d3..4100ec86 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -575,6 +575,9 @@ class MessageLookup extends MessageLookupByLibrary { "personalDietCreating": MessageLookupByLibrary.simpleMessage( "Составление индивидуальной диеты", ), + "personal_diet_set": MessageLookupByLibrary.simpleMessage( + "Персональная диета установлена", + ), "personal_diet_state": MessageLookupByLibrary.simpleMessage("Персональная"), "photo": MessageLookupByLibrary.simpleMessage("Фото"), "physical_fitness": MessageLookupByLibrary.simpleMessage( diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 976ec1b1..19aaa578 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -28,9 +28,10 @@ class S { static const AppLocalizationDelegate delegate = AppLocalizationDelegate(); static Future load(Locale locale) { - final name = (locale.countryCode?.isEmpty ?? false) - ? locale.languageCode - : locale.toString(); + final name = + (locale.countryCode?.isEmpty ?? false) + ? locale.languageCode + : locale.toString(); final localeName = Intl.canonicalizedLocale(name); return initializeMessages(localeName).then((_) { Intl.defaultLocale = localeName; @@ -3568,6 +3569,16 @@ class S { args: [], ); } + + /// `Персональная диета установлена` + String get personal_diet_set { + return Intl.message( + 'Персональная диета установлена', + name: 'personal_diet_set', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 0c1455c1..3991fe61 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -422,6 +422,7 @@ "delete": "Удалить", "cannotDeleteAccount": "Не получилось удалить ваш аккаунт", "resend": "Отправить повторно", - "notifications": "Уведомления" + "notifications": "Уведомления", + "personal_diet_set": "Персональная диета установлена" } From 6ed7faed159788f01434cb8c40d1bc2335403ff2 Mon Sep 17 00:00:00 2001 From: misha Date: Fri, 31 Oct 2025 13:23:13 +0300 Subject: [PATCH 7/7] feat(personalDiets): addde base url from app config for consultation widget --- .../presentation/consultation_widget.dart | 7 ++++--- lib/l10n/intl_en.arb | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart index 3f47db11..fa64362c 100644 --- a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart +++ b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart @@ -1,5 +1,6 @@ +import 'package:eatvio_app/core/app_config.dart'; import 'package:eatvio_app/core/app_router.dart'; -import 'package:eatvio_app/core/const.dart'; +import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart'; @@ -32,7 +33,7 @@ class ConsultationWidget extends StatelessWidget { children: [ CircleAvatar( radius: 30, - backgroundImage: NetworkImage(baseUrl + consultationModel.userProfilePhotoUrl), + backgroundImage: NetworkImage(sl().baseUrl + consultationModel.userProfilePhotoUrl), ), const SizedBox(width: 12), Column( @@ -61,7 +62,7 @@ class ConsultationWidget extends StatelessWidget { children: [ CircleAvatar( radius: 30, - backgroundImage: NetworkImage(baseUrl + consultationModel.userProfilePhotoUrl), + backgroundImage: NetworkImage(sl().baseUrl + consultationModel.userProfilePhotoUrl), ), const SizedBox(width: 12), Column( diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 7528bdd1..28cbf68d 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -407,8 +407,7 @@ "allowAccess": "Разрешить доступ" , "copy": "Скопировать", "reply": "Ответить", - "deleteComment": "Удалить комментарий" - , + "deleteComment": "Удалить комментарий", "personalDietCreating": "Составление индивидуальной диеты", "dietSuggestion": "Предложение диеты", "suggestDiet": "Предложить диету",