From 46841fb502da3f1e2ee665e7b813662cc134a8eb Mon Sep 17 00:00:00 2001 From: misha Date: Thu, 2 Oct 2025 13:49:58 +0300 Subject: [PATCH] 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": "Персональная диета установлена" }