diff --git a/lib/features/create_diet/presentation/create_diet_screen.dart b/lib/features/create_diet/presentation/create_diet_screen.dart index bc1d1445..4678f989 100644 --- a/lib/features/create_diet/presentation/create_diet_screen.dart +++ b/lib/features/create_diet/presentation/create_diet_screen.dart @@ -82,12 +82,7 @@ class _CreateDietScreenContentState extends State { } if (key != null && key.currentContext != null) { - Scrollable.ensureVisible( - key.currentContext!, - duration: const Duration(milliseconds: 500), - curve: Curves.easeInOut, - alignment: 0.1, - ); + Scrollable.ensureVisible(key.currentContext!, duration: const Duration(milliseconds: 500), curve: Curves.easeInOut, alignment: 0.1); } } @@ -213,134 +208,131 @@ class _CreateDietScreenContentState extends State { const SizedBox(height: 12), Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), - child: Column( - children: [ - if (state.isDietBeingEdited) - const Loader() - else - CustomOutlinedButton( - onPressed: () async { - if (state.isDietPublishing) return; - if (widget.diet != null && widget.isEditing == true) { - final dietState = state.dietState; - if (dietState == DietState.draft) { - context.read().setDietState(DietState.active); - } else { - context.read().setDietState(DietState.draft); - } - final result = await context.read().updateDiet(widget.diet!.id); - if (result == 'error') { - if (!context.mounted) return; - showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}'); - return; - } - if (dietState == DietState.draft) { - Future.delayed(const Duration(milliseconds: 500), () { - if (!context.mounted) return; - context.pop(); - showBottomSheetWithBlur( - userRootNavigator: true, - context: context, - child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета'), - ); - }); - } else { - Future.delayed(const Duration(milliseconds: 500), () { - if (!context.mounted) return; - context.pop(); - showBottomSheetWithBlur( - context: context, - child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isDrafted: true), - ); - }); - } - } else { - if (state.dietState != DietState.draft) { - context.read().setDietState(DietState.draft); - } - final result = await context.read().createDiet(); - if (result == 'error') { - if (!context.mounted) return; - showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}'); - } - } - }, - text: state.dietState == DietState.draft && widget.isEditing == true ? s.publish : "В черновик", - height: 52, - buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), - buttonStyle: ButtonStyle( - side: const WidgetStatePropertyAll(BorderSide.none), - backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder), - ), - ), - const SizedBox(height: 12), - CustomOutlinedButton( - onPressed: state.isDietPublishing || state.isDietBeingEdited - ? () {} - : () async { - final diet = await context.read().getDietForPreview(); - if (diet == null) { - // ignore: use_build_context_synchronously - _scrollToFirstError(context.read().state); - return; + child: state.isDietBeingEdited || state.isDietPublishing + ? const Loader() + : Column( + children: [ + CustomOutlinedButton( + onPressed: () async { + if (state.isDietPublishing) return; + if (widget.diet != null && widget.isEditing == true) { + final dietState = state.dietState; + if (dietState == DietState.draft) { + context.read().setDietState(DietState.active); + } else { + context.read().setDietState(DietState.draft); + } + final result = await context.read().updateDiet(widget.diet!.id); + if (result == 'error') { + if (!context.mounted) return; + showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}'); + return; + } + if (dietState == DietState.draft) { + Future.delayed(const Duration(milliseconds: 500), () { + if (!context.mounted) return; + context.pop(); + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета'), + ); + }); + } else { + Future.delayed(const Duration(milliseconds: 500), () { + if (!context.mounted) return; + context.pop(); + showBottomSheetWithBlur( + context: context, + child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isDrafted: true), + ); + }); + } + } else { + if (state.dietState != DietState.draft) { + context.read().setDietState(DietState.draft); + } + final result = await context.read().createDiet(); + if (result == 'error') { + if (!context.mounted) return; + showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}'); + } } - if (!context.mounted) return; - GoRouter.of( - context, - ).pushNamed(DietPreviewScreen.name, extra: {'diet': diet, 'isImageInBase64': state.dietData.imageUrl == null}); }, - text: s.preview, - height: 52, - buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), - buttonStyle: ButtonStyle( - side: const WidgetStatePropertyAll(BorderSide.none), - backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder), + text: state.dietState == DietState.draft && widget.isEditing == true ? s.publish : "В черновик", + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder), + ), + ), + const SizedBox(height: 12), + CustomOutlinedButton( + onPressed: state.isDietPublishing || state.isDietBeingEdited + ? () {} + : () async { + final diet = await context.read().getDietForPreview(); + if (diet == null) { + // ignore: use_build_context_synchronously + _scrollToFirstError(context.read().state); + return; + } + if (!context.mounted) return; + GoRouter.of( + context, + ).pushNamed(DietPreviewScreen.name, extra: {'diet': diet, 'isImageInBase64': state.dietData.imageUrl == null}); + }, + text: s.preview, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder), + ), + ), + const SizedBox(height: 12), + + CustomOutlinedButton( + onPressed: () async { + if (state.isDietBeingEdited) return; + if (widget.diet != null && widget.isEditing == true) { + final result = await context.read().updateDiet(widget.diet!.id); + if (result == 'error') { + if (!context.mounted) return; + showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}'); + } else { + Future.delayed(const Duration(milliseconds: 500), () { + if (!context.mounted) return; + context.pop(); + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isUpdated: true), + ); + }); + } + } else { + final result = await context.read().createDiet(); + if (result == 'validation') { + // ignore: use_build_context_synchronously + _scrollToFirstError(context.read().state); + } else if (result == 'error') { + if (!context.mounted) return; + showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}'); + } + } + }, + text: widget.diet != null && widget.isEditing == true ? s.save : s.publish, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), + ), + ), + ], ), - ), - const SizedBox(height: 12), - if (state.isDietPublishing) - const Loader() - else - CustomOutlinedButton( - onPressed: () async { - if (state.isDietBeingEdited) return; - if (widget.diet != null && widget.isEditing == true) { - final result = await context.read().updateDiet(widget.diet!.id); - if (result == 'error') { - if (!context.mounted) return; - showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}'); - } else { - Future.delayed(const Duration(milliseconds: 500), () { - if (!context.mounted) return; - context.pop(); - showBottomSheetWithBlur( - userRootNavigator: true, - context: context, - child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isUpdated: true), - ); - }); - } - } else { - final result = await context.read().createDiet(); - if (result == 'validation') { - // ignore: use_build_context_synchronously - _scrollToFirstError(context.read().state); - } else if (result == 'error') { - if (!context.mounted) return; - showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}'); - } - } - }, - text: widget.diet != null && widget.isEditing == true ? s.save : s.publish, - height: 52, - buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), - buttonStyle: ButtonStyle( - side: const WidgetStatePropertyAll(BorderSide.none), - backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), - ), - ), - ], - ), ), const SizedBox(height: 20), ],