From 992cb38cddf39b0bccaf939ff5fc4c07d6bf25db Mon Sep 17 00:00:00 2001 From: misha Date: Thu, 6 Nov 2025 08:00:30 +0300 Subject: [PATCH 1/2] feat(personalDiets): fixed ui bugs and added new notification type for personal diet --- .../presentation/widgets/author_card.dart | 23 ++--- .../presentation/widgets/info_bouble.dart | 17 ++-- .../models/notification_model.dart | 31 +++++++ .../notifications_cubit.dart | 6 ++ .../widgets/notification_widget.dart | 67 ++++++++++----- .../service/notifications_service.dart | 6 ++ .../presentation/widgets/payment_banner.dart | 86 ++++++++----------- .../presentation/user_details_screen.dart | 3 +- 8 files changed, 148 insertions(+), 91 deletions(-) diff --git a/lib/features/diets/presentation/widgets/author_card.dart b/lib/features/diets/presentation/widgets/author_card.dart index 3be70bce..3a7c17b8 100644 --- a/lib/features/diets/presentation/widgets/author_card.dart +++ b/lib/features/diets/presentation/widgets/author_card.dart @@ -29,7 +29,7 @@ class AuthorCard extends StatelessWidget { child: Stack( children: [ Padding( - padding: const EdgeInsets.only(left: 16, top: 16, bottom: 24), + padding: const EdgeInsets.only(left: 16, top: 16, bottom: 24, right: 16), child: Column( children: [ ListTile( @@ -68,20 +68,23 @@ class AuthorCard extends StatelessWidget { if (author.authorPlaceInRating != null) InfoBouble( radius: 12, - backgroundColor: appTheme.whiteA700, + backgroundColor: appTheme.cardBackground, children: [ Text('${author.authorPlaceInRating}-й в рейтинге', style: TextStyles.textMMediumAuto.copyWith(color: appTheme.blueA400)), ], ), ] else - GestureDetector( - onTap: () { - GoRouter.of(context).pushNamed(UserDetailsScreen.name, extra: customerProfile!.slug); - }, - child: InfoBouble( - radius: 12, - backgroundColor: appTheme.whiteA700, - children: [Text('Анкета пользователя', style: TextStyles.textMMediumAuto.copyWith(color: appTheme.blueA400))], + Expanded( + child: GestureDetector( + onTap: () { + GoRouter.of(context).pushNamed(UserDetailsScreen.name, extra: customerProfile!.slug); + }, + child: InfoBouble( + radius: 12, + backgroundColor: appTheme.cardBackground, + mainAxisAlignment: MainAxisAlignment.center, + children: [Text('Анкета пользователя', style: TextStyles.textMMediumAuto.copyWith(color: appTheme.blueA400))], + ), ), ), ], diff --git a/lib/features/diets/presentation/widgets/info_bouble.dart b/lib/features/diets/presentation/widgets/info_bouble.dart index d32c534c..1cb12f9d 100644 --- a/lib/features/diets/presentation/widgets/info_bouble.dart +++ b/lib/features/diets/presentation/widgets/info_bouble.dart @@ -2,20 +2,25 @@ import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:flutter/material.dart'; class InfoBouble extends StatelessWidget { - const InfoBouble({super.key, required this.children, this.backgroundColor, this.radius = 100, this.padding}); + const InfoBouble({ + super.key, + required this.children, + this.backgroundColor, + this.radius = 100, + this.padding, + this.mainAxisAlignment = MainAxisAlignment.start, + }); final List children; final Color? backgroundColor; final double radius; final EdgeInsetsGeometry? padding; + final MainAxisAlignment mainAxisAlignment; @override Widget build(BuildContext context) { return Container( padding: padding ?? const EdgeInsets.symmetric(horizontal: 12, vertical: 8.5), - decoration: BoxDecoration( - color: backgroundColor ?? appTheme.gray50, - borderRadius: BorderRadius.circular(radius), - ), - child: Row(mainAxisSize: MainAxisSize.min, children: children), + decoration: BoxDecoration(color: backgroundColor ?? appTheme.gray50, borderRadius: BorderRadius.circular(radius)), + child: Row(mainAxisSize: MainAxisSize.min, mainAxisAlignment: mainAxisAlignment, children: children), ); } } diff --git a/lib/features/notifications/models/notification_model.dart b/lib/features/notifications/models/notification_model.dart index 55c79e51..2d77385f 100644 --- a/lib/features/notifications/models/notification_model.dart +++ b/lib/features/notifications/models/notification_model.dart @@ -1695,6 +1695,35 @@ class DiaryReminderForUsersNotification implements BaseNotificationModel { } } +class PersonalDietIsDefinedToCustomerNotification implements BaseNotificationModel { + @override + final NotificationType type; + @override + final bool isRead; + @override + final DateTime createdAt; + final String dietName; + final int dietId; + + PersonalDietIsDefinedToCustomerNotification({ + required this.type, + required this.isRead, + required this.createdAt, + required this.dietName, + required this.dietId, + }); + + factory PersonalDietIsDefinedToCustomerNotification.fromJson(Map json, NotificationType type, {bool? isRead, String? createdAt}) { + return PersonalDietIsDefinedToCustomerNotification( + type: type, + isRead: isRead ?? false, + createdAt: parseDate(createdAt ?? json['created_at'] ?? DateTime.now().toIso8601String()), + dietName: json['diet_name'] ?? '', + dietId: json['diet_id'], + ); + } +} + enum NotificationType { // Diet related dietCancelled, @@ -1726,6 +1755,7 @@ enum NotificationType { userDailyReportCompleted, chosenPlanFinishedToConsultant, stayOnTrackToCustomer, + personalDietIsDefinedToCustomer, // Comments entityCommented, @@ -1834,6 +1864,7 @@ enum NotificationType { 'chosen-plan-finished-to-consultant' => NotificationType.chosenPlanFinishedToConsultant, 'stay-on-track-to-customer' => NotificationType.stayOnTrackToCustomer, 'diary-reminder-for-users' => NotificationType.diaryReminderForUsers, + 'personal-diet-is-defined-to-customer' => NotificationType.personalDietIsDefinedToCustomer, // Legacy mapping 'App\\Notifications\\Plan\\PlanSubscriptionStartedToAuthor' => NotificationType.planSubscriptionStartedToAuthor, diff --git a/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart b/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart index 8c8c5aaa..110607c0 100644 --- a/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart +++ b/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart @@ -261,6 +261,12 @@ class NotificationsCubit extends Cubit { createdAt: createdAt, ), NotificationType.diaryReminderForUsers => DiaryReminderForUsersNotification.fromJson(notificationJson, type, isRead: isRead, createdAt: createdAt), + NotificationType.personalDietIsDefinedToCustomer => PersonalDietIsDefinedToCustomerNotification.fromJson( + notificationJson, + type, + isRead: isRead, + createdAt: createdAt, + ), NotificationType.unknown => UnknownNotification(type: type), }; } catch (e) { diff --git a/lib/features/notifications/presentation/widgets/notification_widget.dart b/lib/features/notifications/presentation/widgets/notification_widget.dart index 6b675382..c6bd5328 100644 --- a/lib/features/notifications/presentation/widgets/notification_widget.dart +++ b/lib/features/notifications/presentation/widgets/notification_widget.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/core/routing/route_constants.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/utils/date_time_utils.dart'; @@ -113,7 +114,11 @@ class NotificationWidget extends StatelessWidget { notification: notification as ProductStatusUpdatedForAuthorNotification, ), DiaryReminderForUsersNotification() => _DiaryReminderForUsersWidget(notification: notification as DiaryReminderForUsersNotification), + PersonalDietIsDefinedToCustomerNotification() => _PersonalDietIsDefinedToCustomerWidget( + notification: notification as PersonalDietIsDefinedToCustomerNotification, + ), UnknownNotification() => _UnknownNotificationWidget(notification: notification as UnknownNotification), + // TODO: Handle this case. }; } } @@ -364,34 +369,38 @@ class _ChosenPlanFinishedToConsultantWidget extends StatelessWidget { // CardSettingsScreen class _BaseNotificationWidget extends StatelessWidget { - const _BaseNotificationWidget({required this.notificationsText, required this.isRead, required this.createdAt}); + const _BaseNotificationWidget({required this.notificationsText, required this.isRead, required this.createdAt, this.onTap}); final String notificationsText; final bool isRead; final DateTime createdAt; + final void Function()? onTap; @override Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text(notificationsText, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), - ), - if (!isRead) - Container( - decoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle), - width: 8, - height: 8, + return GestureDetector( + onTap: onTap, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Text(notificationsText, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), ), - ], - ), - const SizedBox(height: 4), - Text( - '${createdAt.day} ${_getMonthName(createdAt.month)} ${createdAt.hour.toString().padLeft(2, '0')}:${createdAt.minute.toString().padLeft(2, '0')}', - style: TextStyles.textSMedium.copyWith(color: appTheme.gray600), - ), - ], + if (!isRead) + Container( + decoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle), + width: 8, + height: 8, + ), + ], + ), + const SizedBox(height: 4), + Text( + '${createdAt.day} ${_getMonthName(createdAt.month)} ${createdAt.hour.toString().padLeft(2, '0')}:${createdAt.minute.toString().padLeft(2, '0')}', + style: TextStyles.textSMedium.copyWith(color: appTheme.gray600), + ), + ], + ), ); } @@ -1053,3 +1062,17 @@ class _DiaryReminderForUsersWidget extends StatelessWidget { return _BaseNotificationWidget(isRead: notification.isRead, notificationsText: 'Напоминание о заполнении дневника', createdAt: notification.createdAt); } } + +class _PersonalDietIsDefinedToCustomerWidget extends StatelessWidget { + const _PersonalDietIsDefinedToCustomerWidget({required this.notification}); + final PersonalDietIsDefinedToCustomerNotification notification; + @override + Widget build(BuildContext context) { + return _BaseNotificationWidget( + isRead: notification.isRead, + onTap: () => GoRouter.of(context).push(RouteConstants.aboutDietScreen, extra: {'id': notification.dietId, 'navigateToComments': false}), + notificationsText: 'Персональная диета "${notification.dietName}" установлена', + createdAt: notification.createdAt, + ); + } +} diff --git a/lib/features/notifications/service/notifications_service.dart b/lib/features/notifications/service/notifications_service.dart index 5b3ca78b..1fd5e4d6 100644 --- a/lib/features/notifications/service/notifications_service.dart +++ b/lib/features/notifications/service/notifications_service.dart @@ -407,6 +407,12 @@ class NotificationsService { isRead: readDate != null, createdAt: createdAt, ), + NotificationType.personalDietIsDefinedToCustomer => PersonalDietIsDefinedToCustomerNotification.fromJson( + notificationJson['data'], + type, + isRead: readDate != null, + createdAt: createdAt, + ), NotificationType.unknown => UnknownNotification(type: type, createdAt: parseDate(createdAt)), }; } catch (e) { diff --git a/lib/features/order_info/presentation/widgets/payment_banner.dart b/lib/features/order_info/presentation/widgets/payment_banner.dart index bd570581..5dc56d90 100644 --- a/lib/features/order_info/presentation/widgets/payment_banner.dart +++ b/lib/features/order_info/presentation/widgets/payment_banner.dart @@ -11,11 +11,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; class PaymentBanner extends StatefulWidget { - const PaymentBanner({ - super.key, - required this.successfulPayment, - - }); + const PaymentBanner({super.key, required this.successfulPayment}); final bool successfulPayment; @override @@ -29,8 +25,9 @@ class _PaymentBannerState extends State { final s = S.of(context); final size = MediaQuery.sizeOf(context); return MainBackgroundBouble( - padding: const EdgeInsets.symmetric(vertical: 16), - child: Stack(children: [ + padding: const EdgeInsets.symmetric(vertical: 16), + child: Stack( + children: [ Positioned( left: 0, top: 0, @@ -38,8 +35,9 @@ class _PaymentBannerState extends State { child: Container( width: 4, decoration: BoxDecoration( - color: widget.successfulPayment ? appTheme.blueA400 : appTheme.strongRed, - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), bottomRight: Radius.circular(20))), + color: widget.successfulPayment ? appTheme.blueA400 : appTheme.strongRed, + borderRadius: const BorderRadius.only(topRight: Radius.circular(20), bottomRight: Radius.circular(20)), + ), ), ), Padding( @@ -50,78 +48,65 @@ class _PaymentBannerState extends State { ? [ SizedBox( width: size.width * 0.6, - child: Text( - s.cunsutation_was_paid_successfully, - style: TextStyles.textLSemibold.copyWith(color: appTheme.black), - ), - ), - const SizedBox( - height: 8, + child: Text(s.cunsutation_was_paid_successfully, style: TextStyles.textLSemibold.copyWith(color: appTheme.black)), ), + const SizedBox(height: 8), SizedBox( width: size.width * 0.6, - child: Text( - s.wait_for_start_day, - style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black), - ), - ), - const SizedBox( - height: 16, + child: Text(s.wait_for_start_day, style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black)), ), + const SizedBox(height: 16), isLoading ? const Center(child: Loader()) : CustomOutlinedButton( text: s.go_to_diary, height: 52, buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), - buttonStyle: - ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), + ), onPressed: () async { GoRouter.of(context).pushReplacement('/diary-screen'); }, ), + const SizedBox(height: 10), isLoading ? const Center(child: Loader()) : CustomOutlinedButton( text: s.back_to_chat, height: 52, buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), - buttonStyle: - ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), + ), onPressed: () { GoRouter.of(context).pop(); }, - ) + ), ] : [ SizedBox( width: size.width * 0.6, - child: Text( - s.smth_went_wrong_payment_failed, - style: TextStyles.textLSemibold.copyWith(color: appTheme.black), - ), - ), - const SizedBox( - height: 8, + child: Text(s.smth_went_wrong_payment_failed, style: TextStyles.textLSemibold.copyWith(color: appTheme.black)), ), + const SizedBox(height: 8), SizedBox( width: size.width * 0.6, - child: Text( - s.try_again_2, - style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black), - ), - ), - const SizedBox( - height: 16, + child: Text(s.try_again_2, style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black)), ), + const SizedBox(height: 16), isLoading ? const Center(child: Loader()) : CustomOutlinedButton( text: s.pay, height: 52, buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), - buttonStyle: - ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), + ), onPressed: () async { final planId = context.read().state.chosenPlan?.id; setState(() { @@ -133,16 +118,15 @@ class _PaymentBannerState extends State { }); if (paymentLink != null && planId != null) { if (!context.mounted) return; - GoRouter.of(context).pushReplacement( - PaymentScreen.path, - extra: {'url': paymentLink, 'planId': planId}, - ); + GoRouter.of(context).pushReplacement(PaymentScreen.path, extra: {'url': paymentLink, 'planId': planId}); } }, - ) + ), ], ), - ) - ])); + ), + ], + ), + ); } } diff --git a/lib/features/user_details/presentation/user_details_screen.dart b/lib/features/user_details/presentation/user_details_screen.dart index 46e986f4..a5552802 100644 --- a/lib/features/user_details/presentation/user_details_screen.dart +++ b/lib/features/user_details/presentation/user_details_screen.dart @@ -49,8 +49,7 @@ class _UserDetailsContentState extends State { final List chipsIntervalList = ['1', '3', '6', '12', 'all']; List weightPoints = []; - List circumferencePoints = []; - int _selectedChipIndex = 0; + List circumferencePoints = []; int _selectedChipIndex = 0; int _selectedIntervalChipIndex = 0; bool isMoreOptionsVisible = false; @override From dc400ef5b729ab70d1a5646b1f32f0cd9fb5b9a2 Mon Sep 17 00:00:00 2001 From: misha Date: Mon, 10 Nov 2025 13:50:06 +0300 Subject: [PATCH 2/2] feat(personalDiets): fixed notification and chat banner --- lib/features/chat/presentation/pages/chat_screen.dart | 4 ++-- lib/features/notifications/models/notification_model.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/features/chat/presentation/pages/chat_screen.dart b/lib/features/chat/presentation/pages/chat_screen.dart index 6b17ebb2..b42bf76e 100644 --- a/lib/features/chat/presentation/pages/chat_screen.dart +++ b/lib/features/chat/presentation/pages/chat_screen.dart @@ -135,12 +135,12 @@ class _ChatScreenState extends State { } 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; + } else if (chosenOption?.hasPersonalDiet == true && amIConsultant && chosenPlan.chosenPlanState != ChosenPlanStateEnum.stateDone) { + bannerType = BannerType.setPersonalDiet; } return Scaffold( diff --git a/lib/features/notifications/models/notification_model.dart b/lib/features/notifications/models/notification_model.dart index 2d77385f..cc77616e 100644 --- a/lib/features/notifications/models/notification_model.dart +++ b/lib/features/notifications/models/notification_model.dart @@ -316,7 +316,7 @@ class ChosenPlanFinishedToConsultantNotification implements BaseNotificationMode type: type, planName: json['plan_name'], customerName: json['client_name'], - planId: json['plan_id'], + planId: json['chosen_plan_id'], isRead: isRead ?? false, createdAt: parseDate(createdAt ?? json['created_at'] ?? DateTime.now().toIso8601String()), );