diff --git a/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart b/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart index 4541782b..ded7cb1f 100644 --- a/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart +++ b/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart @@ -237,7 +237,16 @@ class CreateRecipeCubit extends Cubit { final isActiveCookTimeValid = validateActiveCookTime(); final isEnergyPerServingsValid = validateEnergyPerServing(); - return isTitleValid && isDescValid && isImageValid && areServingsValid && isCookTimeValid && isActiveCookTimeValid && isEnergyPerServingsValid; + final isStepsValid = validateSteps(); + + return isTitleValid && + isDescValid && + isImageValid && + areServingsValid && + isCookTimeValid && + isActiveCookTimeValid && + isEnergyPerServingsValid && + isStepsValid; } bool validateTitle() { @@ -328,4 +337,20 @@ class CreateRecipeCubit extends Cubit { Future> getGlossaryListByQuery(String query) async { return await glossaryRepository.getGlossaryListByQuery(query); } + + bool validateSteps() { + bool isValid = true; + for (var step in state.entity.steps) { + if (step.description == null || step.description!.trim().isEmpty) { + isValid = false; + break; + } + } + if (!isValid) { + emit(state.copyWith(stepsValidationError: 'Заполните описание для всех шагов')); + } else { + emit(state.copyWith(stepsValidationError: null)); + } + return isValid; + } } diff --git a/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart b/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart index 41e88611..ef0efe78 100644 --- a/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart +++ b/lib/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart @@ -15,6 +15,7 @@ abstract class CreateRecipeState with _$CreateRecipeState { String? servingsValidationError, String? energyPerServingValidationError, String? imageValidationError, + String? stepsValidationError, }) = _CreateRecipeState; } diff --git a/lib/features/create_recipe/presentation/widgets/steps_widget.dart b/lib/features/create_recipe/presentation/widgets/steps_widget.dart index 7f0e4b87..9beaa707 100644 --- a/lib/features/create_recipe/presentation/widgets/steps_widget.dart +++ b/lib/features/create_recipe/presentation/widgets/steps_widget.dart @@ -55,6 +55,13 @@ class _StepsWidgetState extends State { ), ), ), + if (state.stepsValidationError != null) ...[ + const SizedBox(height: 8), + Text( + state.stepsValidationError!, + style: const TextStyle(color: Colors.red, fontSize: 12), + ), + ], const SizedBox(height: 12), ListView.separated( shrinkWrap: true, diff --git a/lib/features/feed/presentation/pages/feed_screen.dart b/lib/features/feed/presentation/pages/feed_screen.dart index ebf116df..408f00c4 100644 --- a/lib/features/feed/presentation/pages/feed_screen.dart +++ b/lib/features/feed/presentation/pages/feed_screen.dart @@ -228,7 +228,9 @@ class _FeedScreenContentState extends State { ), const SizedBox(width: 12), switch (_selectedChipIndex) { - 1 => AddItemButton(onTap: () => GoRouter.of(context).pushNamed(RecipeCreateScreen.name)), + 1 => AddItemButton( + onTap: state.profile?.roles.contains('consultant') ?? false ? () => GoRouter.of(context).pushNamed(RecipeCreateScreen.name) : null, + ), 2 => AddItemButton( onTap: state.profile?.roles.contains('consultant') ?? false ? () async {