From f6d4ea7df663d3fe853078c53eb281a3270831e0 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2024 11:55:32 +0300 Subject: [PATCH] feat(recipe): add recipe creating --- .../entities/recipe_create_entity.dart | 0 .../bloc/recipe_create_cubit.dart | 300 ---- .../bloc/recipe_create_state.dart | 42 - .../bloc/recipe_create_state.freezed.dart | 1386 ----------------- .../pages/recipe_edit_screen.dart | 516 ------ .../widgets/info_about_recipe_widget.dart | 0 .../presentation/widgets/tags_widget.dart | 0 7 files changed, 2244 deletions(-) create mode 100644 lib/features/recipes/entities/recipe_create_entity.dart delete mode 100644 lib/features/recipes/presentation/bloc/recipe_create_cubit.dart delete mode 100644 lib/features/recipes/presentation/bloc/recipe_create_state.dart delete mode 100644 lib/features/recipes/presentation/bloc/recipe_create_state.freezed.dart delete mode 100644 lib/features/recipes/presentation/pages/recipe_edit_screen.dart create mode 100644 lib/features/recipes/presentation/widgets/info_about_recipe_widget.dart create mode 100644 lib/features/recipes/presentation/widgets/tags_widget.dart diff --git a/lib/features/recipes/entities/recipe_create_entity.dart b/lib/features/recipes/entities/recipe_create_entity.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/recipes/presentation/bloc/recipe_create_cubit.dart b/lib/features/recipes/presentation/bloc/recipe_create_cubit.dart deleted file mode 100644 index e0cd0dce..00000000 --- a/lib/features/recipes/presentation/bloc/recipe_create_cubit.dart +++ /dev/null @@ -1,300 +0,0 @@ -import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart'; -import 'package:eatvio_app/features/recipes/models/ingredient.dart'; -import 'package:eatvio_app/features/recipes/models/recipe_model.dart'; -import 'package:eatvio_app/features/recipes/presentation/bloc/recipe_create_state.dart'; -import 'package:eatvio_app/features/recipes/reporitories/recipe_repository.dart'; -import 'package:eatvio_app/features/recipes/models/product.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:image_picker/image_picker.dart'; - -class RecipeCreateCubit extends Cubit { - final RecipeRepository recipeRepository; - - RecipeCreateCubit({required this.recipeRepository}) : super(const RecipeCreateState.loading()); - - loadRecipeById(String recipeID) async { - emit(const RecipeCreateStateLoading()); - try { - final RecipeModel recipe = await recipeRepository.getRecipe(recipeID); - final List types = [ - SelectionPopupModel(title: 'Первые блюда', value: 'first_meals'), - SelectionPopupModel(title: 'Вторые блюда', value: 'second_meals'), - SelectionPopupModel(title: 'Cалаты', value: 'salads'), - SelectionPopupModel(title: 'Перекусы/закуски', value: 'snacks'), - SelectionPopupModel(title: 'Сладости', value: 'sweets'), - SelectionPopupModel(title: 'Напитки', value: 'drinks'), - SelectionPopupModel(title: 'Прочее', value: 'other'), - ]; - final List cookingTimes = [ - SelectionPopupModel(title: '10 минут', value: 10), - SelectionPopupModel(title: '20 минут', value: 20), - SelectionPopupModel(title: '30 минут', value: 30), - SelectionPopupModel(title: '1 час', value: 60), - SelectionPopupModel(title: '2 часа', value: 120), - SelectionPopupModel(title: '10 дней', value: 14400), - ]; - final List statuses = [ - SelectionPopupModel(title: 'Активна', value: 'active'), - SelectionPopupModel(title: 'Неактивна', value: 'inactive'), - ]; - final selectedType = types.firstWhere( - (type) => type.value == recipe.type, - orElse: () => types[0], - ); - - final selectedCookingTime = cookingTimes.firstWhere( - (time) => time.value == recipe.cooking_time, - orElse: () => cookingTimes[0], - ); - - final selectedStatus = statuses.firstWhere( - (status) => status.value == recipe.state, - orElse: () => statuses[0], - ); - - final stepControllers = recipe.steps?.map((step) { - return TextEditingController(text: step?.description); - }).toList(); - - final stepImages = recipe.steps?.map((step) { - return step?.image != null ? XFile(step!.image!) : null; - }).toList(); - - final ingredients = recipe.ingredients?.map((ingredient) { - return Ingredient( - name: ingredient!.name, - portion: ingredient.portion, - unit: ingredient.unit, - ); - }).toList(); - - emit(RecipeCreateState.loaded( - picker: ImagePicker(), - recipeImage: XFile(recipe.image!), - titleController: TextEditingController(text: recipe.title), - productNameController: TextEditingController(), - ingredientController: TextEditingController(), - stepDescriptionController: TextEditingController(text: recipe.description), - videoLinkController: TextEditingController(text: recipe.video_url), - stepControllers: stepControllers ?? [], - stepImages: stepImages ?? [], - autocompleteList: [], - ingredients: ingredients ?? [], - numberOfSteps: 1, - ingredientAsItems: false, - types: types, - cookingTimes: cookingTimes, - statuses: statuses, - selectedType: selectedType, - selectedCookingTime: selectedCookingTime, - selectedStatus: selectedStatus,),); - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - loadRecipeCreate() { - emit(const RecipeCreateStateLoading()); - try { - final List types = [ - SelectionPopupModel(title: 'Первые блюда', value: 'first_meals'), - SelectionPopupModel(title: 'Вторые блюда', value: 'second_meals'), - SelectionPopupModel(title: 'Cалаты', value: 'salads'), - SelectionPopupModel(title: 'Перекусы/закуски', value: 'snacks'), - SelectionPopupModel(title: 'Сладости', value: 'sweets'), - SelectionPopupModel(title: 'Напитки', value: 'drinks'), - SelectionPopupModel(title: 'Прочее', value: 'other'), - ]; - final List cookingTimes = [ - SelectionPopupModel(title: '10 минут', value: 10), - SelectionPopupModel(title: '20 минут', value: 20), - SelectionPopupModel(title: '30 минут', value: 30), - SelectionPopupModel(title: '1 час', value: 60), - SelectionPopupModel(title: '2 часа', value: 120), - SelectionPopupModel(title: '10 дней', value: 14400), - ]; - final List statuses = [ - SelectionPopupModel(title: 'Активна', value: 'active'), - SelectionPopupModel(title: 'Неактивна', value: 'inactive'), - ]; - emit(RecipeCreateState.loaded( - picker: ImagePicker(), - titleController: TextEditingController(), - productNameController: TextEditingController(), - ingredientController: TextEditingController(), - stepDescriptionController: TextEditingController(), - videoLinkController: TextEditingController(), - stepControllers: [TextEditingController()], - stepImages: [null], - autocompleteList: [], - ingredients: [], - numberOfSteps: 1, - ingredientAsItems: false, - types: types, - cookingTimes: cookingTimes, - statuses: statuses, - selectedType: types[0], - selectedCookingTime: cookingTimes[0], - selectedStatus: statuses[0],),); - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - publishRecipe(RecipeModel recipe) async { - await recipeRepository.publishRecipe(recipe); - } - - editRecipe(RecipeModel recipe, String id) async { - await recipeRepository.editRecipe(recipe, id); - } - - uploadRecipeImage(XFile? pickedFile) { - try { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - var updatedState = currentState.copyWith( - recipeImage: pickedFile, - ); - emit(updatedState); - } - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - uploadStepImage(XFile? pickedFile, int stepNumber) { - try { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - - var updatedStepImages = List.from(currentState.stepImages); - - if (stepNumber >= 0 && stepNumber < updatedStepImages.length) { - updatedStepImages[stepNumber] = pickedFile; - } - - var updatedState = currentState.copyWith( - stepImages: updatedStepImages, - ); - - emit(updatedState); - } - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - switchUnits(bool value) { - try { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - var updatedState = currentState.copyWith(ingredientAsItems: value); - emit(updatedState); - } - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - addIngredient(Ingredient ingredient) { - try { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - - bool ingredientExists = currentState.ingredients.any((existingIngredient) => existingIngredient.name == ingredient.name); - - if (ingredientExists) { - emit(RecipeCreateState.error(errorMessage: 'Ингредиент уже существует.')); - return; - } - - List newIngredients = List.from(currentState.ingredients); - newIngredients.add(ingredient); - - var updatedState = currentState.copyWith(ingredients: newIngredients); - emit(updatedState); - } - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - addStep() { - try { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - List newStepImages = List.from(currentState.stepImages); - newStepImages.add(null); - List newStepControllers = List.from(currentState.stepControllers); - newStepControllers.add(TextEditingController()); - var updatedState = currentState.copyWith(stepImages: newStepImages, stepControllers: newStepControllers, numberOfSteps: currentState.numberOfSteps + 1); - emit(updatedState); - } - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - removeStep() { - try { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - List newStepImages = List.from(currentState.stepImages); - newStepImages.removeLast(); - List newStepControllers = List.from(currentState.stepControllers); - newStepControllers.removeLast(); - var updatedState = currentState.copyWith(stepImages: newStepImages, stepControllers: newStepControllers, numberOfSteps: currentState.numberOfSteps - 1); - emit(updatedState); - } - } catch (e) { - emit(RecipeCreateState.error(errorMessage: e.toString())); - } - } - - inputProduct(String input) async { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - - final Map> productNutritionalValues = await recipeRepository.inputProduct(input); - - var updatedState = currentState.copyWith( - productNameController: TextEditingController(text: input), - autocompleteList: productNutritionalValues['product_nutritional_value'] ?? [], - ); - - emit(updatedState); - } - } - - changeType(SelectionPopupModel type) { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - RecipeCreateStateLoaded updatedState = currentState.copyWith( - selectedType: type, - ); - emit(updatedState); - } - } - - changeStatus(SelectionPopupModel status) { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - RecipeCreateStateLoaded updatedState = currentState.copyWith( - selectedStatus: status, - ); - emit(updatedState); - } - } - - changeCookingTime(SelectionPopupModel cookingTime) { - if (state is RecipeCreateStateLoaded) { - var currentState = state as RecipeCreateStateLoaded; - RecipeCreateStateLoaded updatedState = currentState.copyWith( - selectedCookingTime: cookingTime, - ); - emit(updatedState); - } - } -} diff --git a/lib/features/recipes/presentation/bloc/recipe_create_state.dart b/lib/features/recipes/presentation/bloc/recipe_create_state.dart deleted file mode 100644 index 8e84b19b..00000000 --- a/lib/features/recipes/presentation/bloc/recipe_create_state.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart'; -import 'package:eatvio_app/features/recipes/models/recipe_model.dart'; -import 'package:eatvio_app/features/recipes/models/ingredient.dart'; -import 'package:eatvio_app/features/recipes/models/product.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:image_picker/image_picker.dart'; -part 'recipe_create_state.freezed.dart'; - -@freezed -abstract class RecipeCreateState with _$RecipeCreateState { - const factory RecipeCreateState() = _RecipeCreateState; - - const factory RecipeCreateState.loading() = RecipeCreateStateLoading; - - const factory RecipeCreateState.loaded({ - RecipeModel? recipe, - required ImagePicker picker, - required TextEditingController titleController, - required TextEditingController productNameController, - required TextEditingController ingredientController, - required TextEditingController stepDescriptionController, - required TextEditingController videoLinkController, - required List stepControllers, - XFile? recipeImage, - required List stepImages, - required List ingredients, - required List autocompleteList, - required int numberOfSteps, - required bool ingredientAsItems, - required List types, - required List cookingTimes, - required List statuses, - required SelectionPopupModel selectedType, - required SelectionPopupModel selectedCookingTime, - required SelectionPopupModel selectedStatus, - }) = RecipeCreateStateLoaded; - - const factory RecipeCreateState.error({ - required String errorMessage, - }) = RecipeCreateStateError; -} diff --git a/lib/features/recipes/presentation/bloc/recipe_create_state.freezed.dart b/lib/features/recipes/presentation/bloc/recipe_create_state.freezed.dart deleted file mode 100644 index 672872e2..00000000 --- a/lib/features/recipes/presentation/bloc/recipe_create_state.freezed.dart +++ /dev/null @@ -1,1386 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'recipe_create_state.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$RecipeCreateState { - @optionalTypeArgs - TResult when( - TResult Function() $default, { - required TResult Function() loading, - required TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus) - loaded, - required TResult Function(String errorMessage) error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function()? $default, { - TResult? Function()? loading, - TResult? Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult? Function(String errorMessage)? error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen( - TResult Function()? $default, { - TResult Function()? loading, - TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult Function(String errorMessage)? error, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map( - TResult Function(_RecipeCreateState value) $default, { - required TResult Function(RecipeCreateStateLoading value) loading, - required TResult Function(RecipeCreateStateLoaded value) loaded, - required TResult Function(RecipeCreateStateError value) error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_RecipeCreateState value)? $default, { - TResult? Function(RecipeCreateStateLoading value)? loading, - TResult? Function(RecipeCreateStateLoaded value)? loaded, - TResult? Function(RecipeCreateStateError value)? error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap( - TResult Function(_RecipeCreateState value)? $default, { - TResult Function(RecipeCreateStateLoading value)? loading, - TResult Function(RecipeCreateStateLoaded value)? loaded, - TResult Function(RecipeCreateStateError value)? error, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $RecipeCreateStateCopyWith<$Res> { - factory $RecipeCreateStateCopyWith( - RecipeCreateState value, $Res Function(RecipeCreateState) then) = - _$RecipeCreateStateCopyWithImpl<$Res, RecipeCreateState>; -} - -/// @nodoc -class _$RecipeCreateStateCopyWithImpl<$Res, $Val extends RecipeCreateState> - implements $RecipeCreateStateCopyWith<$Res> { - _$RecipeCreateStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$RecipeCreateStateImplCopyWith<$Res> { - factory _$$RecipeCreateStateImplCopyWith(_$RecipeCreateStateImpl value, - $Res Function(_$RecipeCreateStateImpl) then) = - __$$RecipeCreateStateImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$RecipeCreateStateImplCopyWithImpl<$Res> - extends _$RecipeCreateStateCopyWithImpl<$Res, _$RecipeCreateStateImpl> - implements _$$RecipeCreateStateImplCopyWith<$Res> { - __$$RecipeCreateStateImplCopyWithImpl(_$RecipeCreateStateImpl _value, - $Res Function(_$RecipeCreateStateImpl) _then) - : super(_value, _then); - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$RecipeCreateStateImpl implements _RecipeCreateState { - const _$RecipeCreateStateImpl(); - - @override - String toString() { - return 'RecipeCreateState()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$RecipeCreateStateImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when( - TResult Function() $default, { - required TResult Function() loading, - required TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus) - loaded, - required TResult Function(String errorMessage) error, - }) { - return $default(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function()? $default, { - TResult? Function()? loading, - TResult? Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult? Function(String errorMessage)? error, - }) { - return $default?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen( - TResult Function()? $default, { - TResult Function()? loading, - TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult Function(String errorMessage)? error, - required TResult orElse(), - }) { - if ($default != null) { - return $default(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map( - TResult Function(_RecipeCreateState value) $default, { - required TResult Function(RecipeCreateStateLoading value) loading, - required TResult Function(RecipeCreateStateLoaded value) loaded, - required TResult Function(RecipeCreateStateError value) error, - }) { - return $default(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_RecipeCreateState value)? $default, { - TResult? Function(RecipeCreateStateLoading value)? loading, - TResult? Function(RecipeCreateStateLoaded value)? loaded, - TResult? Function(RecipeCreateStateError value)? error, - }) { - return $default?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap( - TResult Function(_RecipeCreateState value)? $default, { - TResult Function(RecipeCreateStateLoading value)? loading, - TResult Function(RecipeCreateStateLoaded value)? loaded, - TResult Function(RecipeCreateStateError value)? error, - required TResult orElse(), - }) { - if ($default != null) { - return $default(this); - } - return orElse(); - } -} - -abstract class _RecipeCreateState implements RecipeCreateState { - const factory _RecipeCreateState() = _$RecipeCreateStateImpl; -} - -/// @nodoc -abstract class _$$RecipeCreateStateLoadingImplCopyWith<$Res> { - factory _$$RecipeCreateStateLoadingImplCopyWith( - _$RecipeCreateStateLoadingImpl value, - $Res Function(_$RecipeCreateStateLoadingImpl) then) = - __$$RecipeCreateStateLoadingImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$RecipeCreateStateLoadingImplCopyWithImpl<$Res> - extends _$RecipeCreateStateCopyWithImpl<$Res, - _$RecipeCreateStateLoadingImpl> - implements _$$RecipeCreateStateLoadingImplCopyWith<$Res> { - __$$RecipeCreateStateLoadingImplCopyWithImpl( - _$RecipeCreateStateLoadingImpl _value, - $Res Function(_$RecipeCreateStateLoadingImpl) _then) - : super(_value, _then); - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$RecipeCreateStateLoadingImpl implements RecipeCreateStateLoading { - const _$RecipeCreateStateLoadingImpl(); - - @override - String toString() { - return 'RecipeCreateState.loading()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$RecipeCreateStateLoadingImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when( - TResult Function() $default, { - required TResult Function() loading, - required TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus) - loaded, - required TResult Function(String errorMessage) error, - }) { - return loading(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function()? $default, { - TResult? Function()? loading, - TResult? Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult? Function(String errorMessage)? error, - }) { - return loading?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen( - TResult Function()? $default, { - TResult Function()? loading, - TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult Function(String errorMessage)? error, - required TResult orElse(), - }) { - if (loading != null) { - return loading(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map( - TResult Function(_RecipeCreateState value) $default, { - required TResult Function(RecipeCreateStateLoading value) loading, - required TResult Function(RecipeCreateStateLoaded value) loaded, - required TResult Function(RecipeCreateStateError value) error, - }) { - return loading(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_RecipeCreateState value)? $default, { - TResult? Function(RecipeCreateStateLoading value)? loading, - TResult? Function(RecipeCreateStateLoaded value)? loaded, - TResult? Function(RecipeCreateStateError value)? error, - }) { - return loading?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap( - TResult Function(_RecipeCreateState value)? $default, { - TResult Function(RecipeCreateStateLoading value)? loading, - TResult Function(RecipeCreateStateLoaded value)? loaded, - TResult Function(RecipeCreateStateError value)? error, - required TResult orElse(), - }) { - if (loading != null) { - return loading(this); - } - return orElse(); - } -} - -abstract class RecipeCreateStateLoading implements RecipeCreateState { - const factory RecipeCreateStateLoading() = _$RecipeCreateStateLoadingImpl; -} - -/// @nodoc -abstract class _$$RecipeCreateStateLoadedImplCopyWith<$Res> { - factory _$$RecipeCreateStateLoadedImplCopyWith( - _$RecipeCreateStateLoadedImpl value, - $Res Function(_$RecipeCreateStateLoadedImpl) then) = - __$$RecipeCreateStateLoadedImplCopyWithImpl<$Res>; - @useResult - $Res call( - {RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus}); - - $RecipeModelCopyWith<$Res>? get recipe; - $SelectionPopupModelCopyWith<$Res> get selectedType; - $SelectionPopupModelCopyWith<$Res> get selectedCookingTime; - $SelectionPopupModelCopyWith<$Res> get selectedStatus; -} - -/// @nodoc -class __$$RecipeCreateStateLoadedImplCopyWithImpl<$Res> - extends _$RecipeCreateStateCopyWithImpl<$Res, _$RecipeCreateStateLoadedImpl> - implements _$$RecipeCreateStateLoadedImplCopyWith<$Res> { - __$$RecipeCreateStateLoadedImplCopyWithImpl( - _$RecipeCreateStateLoadedImpl _value, - $Res Function(_$RecipeCreateStateLoadedImpl) _then) - : super(_value, _then); - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? recipe = freezed, - Object? picker = null, - Object? titleController = null, - Object? productNameController = null, - Object? ingredientController = null, - Object? stepDescriptionController = null, - Object? videoLinkController = null, - Object? stepControllers = null, - Object? recipeImage = freezed, - Object? stepImages = null, - Object? ingredients = null, - Object? autocompleteList = null, - Object? numberOfSteps = null, - Object? ingredientAsItems = null, - Object? types = null, - Object? cookingTimes = null, - Object? statuses = null, - Object? selectedType = null, - Object? selectedCookingTime = null, - Object? selectedStatus = null, - }) { - return _then(_$RecipeCreateStateLoadedImpl( - recipe: freezed == recipe - ? _value.recipe - : recipe // ignore: cast_nullable_to_non_nullable - as RecipeModel?, - picker: null == picker - ? _value.picker - : picker // ignore: cast_nullable_to_non_nullable - as ImagePicker, - titleController: null == titleController - ? _value.titleController - : titleController // ignore: cast_nullable_to_non_nullable - as TextEditingController, - productNameController: null == productNameController - ? _value.productNameController - : productNameController // ignore: cast_nullable_to_non_nullable - as TextEditingController, - ingredientController: null == ingredientController - ? _value.ingredientController - : ingredientController // ignore: cast_nullable_to_non_nullable - as TextEditingController, - stepDescriptionController: null == stepDescriptionController - ? _value.stepDescriptionController - : stepDescriptionController // ignore: cast_nullable_to_non_nullable - as TextEditingController, - videoLinkController: null == videoLinkController - ? _value.videoLinkController - : videoLinkController // ignore: cast_nullable_to_non_nullable - as TextEditingController, - stepControllers: null == stepControllers - ? _value._stepControllers - : stepControllers // ignore: cast_nullable_to_non_nullable - as List, - recipeImage: freezed == recipeImage - ? _value.recipeImage - : recipeImage // ignore: cast_nullable_to_non_nullable - as XFile?, - stepImages: null == stepImages - ? _value._stepImages - : stepImages // ignore: cast_nullable_to_non_nullable - as List, - ingredients: null == ingredients - ? _value._ingredients - : ingredients // ignore: cast_nullable_to_non_nullable - as List, - autocompleteList: null == autocompleteList - ? _value._autocompleteList - : autocompleteList // ignore: cast_nullable_to_non_nullable - as List, - numberOfSteps: null == numberOfSteps - ? _value.numberOfSteps - : numberOfSteps // ignore: cast_nullable_to_non_nullable - as int, - ingredientAsItems: null == ingredientAsItems - ? _value.ingredientAsItems - : ingredientAsItems // ignore: cast_nullable_to_non_nullable - as bool, - types: null == types - ? _value._types - : types // ignore: cast_nullable_to_non_nullable - as List, - cookingTimes: null == cookingTimes - ? _value._cookingTimes - : cookingTimes // ignore: cast_nullable_to_non_nullable - as List, - statuses: null == statuses - ? _value._statuses - : statuses // ignore: cast_nullable_to_non_nullable - as List, - selectedType: null == selectedType - ? _value.selectedType - : selectedType // ignore: cast_nullable_to_non_nullable - as SelectionPopupModel, - selectedCookingTime: null == selectedCookingTime - ? _value.selectedCookingTime - : selectedCookingTime // ignore: cast_nullable_to_non_nullable - as SelectionPopupModel, - selectedStatus: null == selectedStatus - ? _value.selectedStatus - : selectedStatus // ignore: cast_nullable_to_non_nullable - as SelectionPopupModel, - )); - } - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $RecipeModelCopyWith<$Res>? get recipe { - if (_value.recipe == null) { - return null; - } - - return $RecipeModelCopyWith<$Res>(_value.recipe!, (value) { - return _then(_value.copyWith(recipe: value)); - }); - } - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $SelectionPopupModelCopyWith<$Res> get selectedType { - return $SelectionPopupModelCopyWith<$Res>(_value.selectedType, (value) { - return _then(_value.copyWith(selectedType: value)); - }); - } - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $SelectionPopupModelCopyWith<$Res> get selectedCookingTime { - return $SelectionPopupModelCopyWith<$Res>(_value.selectedCookingTime, - (value) { - return _then(_value.copyWith(selectedCookingTime: value)); - }); - } - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $SelectionPopupModelCopyWith<$Res> get selectedStatus { - return $SelectionPopupModelCopyWith<$Res>(_value.selectedStatus, (value) { - return _then(_value.copyWith(selectedStatus: value)); - }); - } -} - -/// @nodoc - -class _$RecipeCreateStateLoadedImpl implements RecipeCreateStateLoaded { - const _$RecipeCreateStateLoadedImpl( - {this.recipe, - required this.picker, - required this.titleController, - required this.productNameController, - required this.ingredientController, - required this.stepDescriptionController, - required this.videoLinkController, - required final List stepControllers, - this.recipeImage, - required final List stepImages, - required final List ingredients, - required final List autocompleteList, - required this.numberOfSteps, - required this.ingredientAsItems, - required final List types, - required final List cookingTimes, - required final List statuses, - required this.selectedType, - required this.selectedCookingTime, - required this.selectedStatus}) - : _stepControllers = stepControllers, - _stepImages = stepImages, - _ingredients = ingredients, - _autocompleteList = autocompleteList, - _types = types, - _cookingTimes = cookingTimes, - _statuses = statuses; - - @override - final RecipeModel? recipe; - @override - final ImagePicker picker; - @override - final TextEditingController titleController; - @override - final TextEditingController productNameController; - @override - final TextEditingController ingredientController; - @override - final TextEditingController stepDescriptionController; - @override - final TextEditingController videoLinkController; - final List _stepControllers; - @override - List get stepControllers { - if (_stepControllers is EqualUnmodifiableListView) return _stepControllers; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_stepControllers); - } - - @override - final XFile? recipeImage; - final List _stepImages; - @override - List get stepImages { - if (_stepImages is EqualUnmodifiableListView) return _stepImages; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_stepImages); - } - - final List _ingredients; - @override - List get ingredients { - if (_ingredients is EqualUnmodifiableListView) return _ingredients; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_ingredients); - } - - final List _autocompleteList; - @override - List get autocompleteList { - if (_autocompleteList is EqualUnmodifiableListView) - return _autocompleteList; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_autocompleteList); - } - - @override - final int numberOfSteps; - @override - final bool ingredientAsItems; - final List _types; - @override - List get types { - if (_types is EqualUnmodifiableListView) return _types; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_types); - } - - final List _cookingTimes; - @override - List get cookingTimes { - if (_cookingTimes is EqualUnmodifiableListView) return _cookingTimes; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_cookingTimes); - } - - final List _statuses; - @override - List get statuses { - if (_statuses is EqualUnmodifiableListView) return _statuses; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_statuses); - } - - @override - final SelectionPopupModel selectedType; - @override - final SelectionPopupModel selectedCookingTime; - @override - final SelectionPopupModel selectedStatus; - - @override - String toString() { - return 'RecipeCreateState.loaded(recipe: $recipe, picker: $picker, titleController: $titleController, productNameController: $productNameController, ingredientController: $ingredientController, stepDescriptionController: $stepDescriptionController, videoLinkController: $videoLinkController, stepControllers: $stepControllers, recipeImage: $recipeImage, stepImages: $stepImages, ingredients: $ingredients, autocompleteList: $autocompleteList, numberOfSteps: $numberOfSteps, ingredientAsItems: $ingredientAsItems, types: $types, cookingTimes: $cookingTimes, statuses: $statuses, selectedType: $selectedType, selectedCookingTime: $selectedCookingTime, selectedStatus: $selectedStatus)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$RecipeCreateStateLoadedImpl && - (identical(other.recipe, recipe) || other.recipe == recipe) && - (identical(other.picker, picker) || other.picker == picker) && - (identical(other.titleController, titleController) || - other.titleController == titleController) && - (identical(other.productNameController, productNameController) || - other.productNameController == productNameController) && - (identical(other.ingredientController, ingredientController) || - other.ingredientController == ingredientController) && - (identical(other.stepDescriptionController, - stepDescriptionController) || - other.stepDescriptionController == stepDescriptionController) && - (identical(other.videoLinkController, videoLinkController) || - other.videoLinkController == videoLinkController) && - const DeepCollectionEquality() - .equals(other._stepControllers, _stepControllers) && - (identical(other.recipeImage, recipeImage) || - other.recipeImage == recipeImage) && - const DeepCollectionEquality() - .equals(other._stepImages, _stepImages) && - const DeepCollectionEquality() - .equals(other._ingredients, _ingredients) && - const DeepCollectionEquality() - .equals(other._autocompleteList, _autocompleteList) && - (identical(other.numberOfSteps, numberOfSteps) || - other.numberOfSteps == numberOfSteps) && - (identical(other.ingredientAsItems, ingredientAsItems) || - other.ingredientAsItems == ingredientAsItems) && - const DeepCollectionEquality().equals(other._types, _types) && - const DeepCollectionEquality() - .equals(other._cookingTimes, _cookingTimes) && - const DeepCollectionEquality().equals(other._statuses, _statuses) && - (identical(other.selectedType, selectedType) || - other.selectedType == selectedType) && - (identical(other.selectedCookingTime, selectedCookingTime) || - other.selectedCookingTime == selectedCookingTime) && - (identical(other.selectedStatus, selectedStatus) || - other.selectedStatus == selectedStatus)); - } - - @override - int get hashCode => Object.hashAll([ - runtimeType, - recipe, - picker, - titleController, - productNameController, - ingredientController, - stepDescriptionController, - videoLinkController, - const DeepCollectionEquality().hash(_stepControllers), - recipeImage, - const DeepCollectionEquality().hash(_stepImages), - const DeepCollectionEquality().hash(_ingredients), - const DeepCollectionEquality().hash(_autocompleteList), - numberOfSteps, - ingredientAsItems, - const DeepCollectionEquality().hash(_types), - const DeepCollectionEquality().hash(_cookingTimes), - const DeepCollectionEquality().hash(_statuses), - selectedType, - selectedCookingTime, - selectedStatus - ]); - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$RecipeCreateStateLoadedImplCopyWith<_$RecipeCreateStateLoadedImpl> - get copyWith => __$$RecipeCreateStateLoadedImplCopyWithImpl< - _$RecipeCreateStateLoadedImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when( - TResult Function() $default, { - required TResult Function() loading, - required TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus) - loaded, - required TResult Function(String errorMessage) error, - }) { - return loaded( - recipe, - picker, - titleController, - productNameController, - ingredientController, - stepDescriptionController, - videoLinkController, - stepControllers, - recipeImage, - stepImages, - ingredients, - autocompleteList, - numberOfSteps, - ingredientAsItems, - types, - cookingTimes, - statuses, - selectedType, - selectedCookingTime, - selectedStatus); - } - - @override - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function()? $default, { - TResult? Function()? loading, - TResult? Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult? Function(String errorMessage)? error, - }) { - return loaded?.call( - recipe, - picker, - titleController, - productNameController, - ingredientController, - stepDescriptionController, - videoLinkController, - stepControllers, - recipeImage, - stepImages, - ingredients, - autocompleteList, - numberOfSteps, - ingredientAsItems, - types, - cookingTimes, - statuses, - selectedType, - selectedCookingTime, - selectedStatus); - } - - @override - @optionalTypeArgs - TResult maybeWhen( - TResult Function()? $default, { - TResult Function()? loading, - TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult Function(String errorMessage)? error, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded( - recipe, - picker, - titleController, - productNameController, - ingredientController, - stepDescriptionController, - videoLinkController, - stepControllers, - recipeImage, - stepImages, - ingredients, - autocompleteList, - numberOfSteps, - ingredientAsItems, - types, - cookingTimes, - statuses, - selectedType, - selectedCookingTime, - selectedStatus); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map( - TResult Function(_RecipeCreateState value) $default, { - required TResult Function(RecipeCreateStateLoading value) loading, - required TResult Function(RecipeCreateStateLoaded value) loaded, - required TResult Function(RecipeCreateStateError value) error, - }) { - return loaded(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_RecipeCreateState value)? $default, { - TResult? Function(RecipeCreateStateLoading value)? loading, - TResult? Function(RecipeCreateStateLoaded value)? loaded, - TResult? Function(RecipeCreateStateError value)? error, - }) { - return loaded?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap( - TResult Function(_RecipeCreateState value)? $default, { - TResult Function(RecipeCreateStateLoading value)? loading, - TResult Function(RecipeCreateStateLoaded value)? loaded, - TResult Function(RecipeCreateStateError value)? error, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(this); - } - return orElse(); - } -} - -abstract class RecipeCreateStateLoaded implements RecipeCreateState { - const factory RecipeCreateStateLoaded( - {final RecipeModel? recipe, - required final ImagePicker picker, - required final TextEditingController titleController, - required final TextEditingController productNameController, - required final TextEditingController ingredientController, - required final TextEditingController stepDescriptionController, - required final TextEditingController videoLinkController, - required final List stepControllers, - final XFile? recipeImage, - required final List stepImages, - required final List ingredients, - required final List autocompleteList, - required final int numberOfSteps, - required final bool ingredientAsItems, - required final List types, - required final List cookingTimes, - required final List statuses, - required final SelectionPopupModel selectedType, - required final SelectionPopupModel selectedCookingTime, - required final SelectionPopupModel selectedStatus}) = - _$RecipeCreateStateLoadedImpl; - - RecipeModel? get recipe; - ImagePicker get picker; - TextEditingController get titleController; - TextEditingController get productNameController; - TextEditingController get ingredientController; - TextEditingController get stepDescriptionController; - TextEditingController get videoLinkController; - List get stepControllers; - XFile? get recipeImage; - List get stepImages; - List get ingredients; - List get autocompleteList; - int get numberOfSteps; - bool get ingredientAsItems; - List get types; - List get cookingTimes; - List get statuses; - SelectionPopupModel get selectedType; - SelectionPopupModel get selectedCookingTime; - SelectionPopupModel get selectedStatus; - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$RecipeCreateStateLoadedImplCopyWith<_$RecipeCreateStateLoadedImpl> - get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$RecipeCreateStateErrorImplCopyWith<$Res> { - factory _$$RecipeCreateStateErrorImplCopyWith( - _$RecipeCreateStateErrorImpl value, - $Res Function(_$RecipeCreateStateErrorImpl) then) = - __$$RecipeCreateStateErrorImplCopyWithImpl<$Res>; - @useResult - $Res call({String errorMessage}); -} - -/// @nodoc -class __$$RecipeCreateStateErrorImplCopyWithImpl<$Res> - extends _$RecipeCreateStateCopyWithImpl<$Res, _$RecipeCreateStateErrorImpl> - implements _$$RecipeCreateStateErrorImplCopyWith<$Res> { - __$$RecipeCreateStateErrorImplCopyWithImpl( - _$RecipeCreateStateErrorImpl _value, - $Res Function(_$RecipeCreateStateErrorImpl) _then) - : super(_value, _then); - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? errorMessage = null, - }) { - return _then(_$RecipeCreateStateErrorImpl( - errorMessage: null == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc - -class _$RecipeCreateStateErrorImpl implements RecipeCreateStateError { - const _$RecipeCreateStateErrorImpl({required this.errorMessage}); - - @override - final String errorMessage; - - @override - String toString() { - return 'RecipeCreateState.error(errorMessage: $errorMessage)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$RecipeCreateStateErrorImpl && - (identical(other.errorMessage, errorMessage) || - other.errorMessage == errorMessage)); - } - - @override - int get hashCode => Object.hash(runtimeType, errorMessage); - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$RecipeCreateStateErrorImplCopyWith<_$RecipeCreateStateErrorImpl> - get copyWith => __$$RecipeCreateStateErrorImplCopyWithImpl< - _$RecipeCreateStateErrorImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when( - TResult Function() $default, { - required TResult Function() loading, - required TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus) - loaded, - required TResult Function(String errorMessage) error, - }) { - return error(errorMessage); - } - - @override - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function()? $default, { - TResult? Function()? loading, - TResult? Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult? Function(String errorMessage)? error, - }) { - return error?.call(errorMessage); - } - - @override - @optionalTypeArgs - TResult maybeWhen( - TResult Function()? $default, { - TResult Function()? loading, - TResult Function( - RecipeModel? recipe, - ImagePicker picker, - TextEditingController titleController, - TextEditingController productNameController, - TextEditingController ingredientController, - TextEditingController stepDescriptionController, - TextEditingController videoLinkController, - List stepControllers, - XFile? recipeImage, - List stepImages, - List ingredients, - List autocompleteList, - int numberOfSteps, - bool ingredientAsItems, - List types, - List cookingTimes, - List statuses, - SelectionPopupModel selectedType, - SelectionPopupModel selectedCookingTime, - SelectionPopupModel selectedStatus)? - loaded, - TResult Function(String errorMessage)? error, - required TResult orElse(), - }) { - if (error != null) { - return error(errorMessage); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map( - TResult Function(_RecipeCreateState value) $default, { - required TResult Function(RecipeCreateStateLoading value) loading, - required TResult Function(RecipeCreateStateLoaded value) loaded, - required TResult Function(RecipeCreateStateError value) error, - }) { - return error(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_RecipeCreateState value)? $default, { - TResult? Function(RecipeCreateStateLoading value)? loading, - TResult? Function(RecipeCreateStateLoaded value)? loaded, - TResult? Function(RecipeCreateStateError value)? error, - }) { - return error?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap( - TResult Function(_RecipeCreateState value)? $default, { - TResult Function(RecipeCreateStateLoading value)? loading, - TResult Function(RecipeCreateStateLoaded value)? loaded, - TResult Function(RecipeCreateStateError value)? error, - required TResult orElse(), - }) { - if (error != null) { - return error(this); - } - return orElse(); - } -} - -abstract class RecipeCreateStateError implements RecipeCreateState { - const factory RecipeCreateStateError({required final String errorMessage}) = - _$RecipeCreateStateErrorImpl; - - String get errorMessage; - - /// Create a copy of RecipeCreateState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$RecipeCreateStateErrorImplCopyWith<_$RecipeCreateStateErrorImpl> - get copyWith => throw _privateConstructorUsedError; -} diff --git a/lib/features/recipes/presentation/pages/recipe_edit_screen.dart b/lib/features/recipes/presentation/pages/recipe_edit_screen.dart deleted file mode 100644 index dffccf3f..00000000 --- a/lib/features/recipes/presentation/pages/recipe_edit_screen.dart +++ /dev/null @@ -1,516 +0,0 @@ -import 'package:eatvio_app/core/const.dart'; -import 'package:eatvio_app/core/theme/app_decoration.dart'; -import 'package:eatvio_app/core/widgets/custom_drop_down.dart'; -import 'package:eatvio_app/core/widgets/loader.dart'; -import 'package:eatvio_app/features/recipes/models/product.dart'; -import 'package:eatvio_app/features/recipes/models/ingredient.dart'; -import 'package:eatvio_app/features/recipes/models/recipe_model.dart'; -import 'package:eatvio_app/features/recipes/models/step.dart' as step; -import 'package:eatvio_app/features/recipes/presentation/bloc/recipe_create_cubit.dart'; -import 'package:eatvio_app/features/recipes/presentation/bloc/recipe_create_state.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_text_form_field.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:image_picker/image_picker.dart'; - -// ignore: must_be_immutable -class RecipeEditScreen extends StatelessWidget { - final String recipeID; - - const RecipeEditScreen({ - required this.recipeID, - super.key, - }); - - Widget build(BuildContext context) { - if (recipeID != "0") { - context.read().loadRecipeById(recipeID); - } - return BlocBuilder( - builder: (context, state) { - if (state is RecipeCreateStateLoaded) { - return _buildRecipeCreate(context, state); - } else if (state is RecipeCreateStateLoading) { - return Scaffold( - body: Loader(), - ); - } else if (state is RecipeCreateStateError) { - return Scaffold( - body: Padding( - padding: const EdgeInsets.all(16), - child: Center( - child: Text(state.errorMessage), - ), - ), - ); - } else - return Scaffold( - body: Padding( - padding: const EdgeInsets.all(16), - child: Center( - child: Text("Неопределенная ошибка"), - ), - ), - ); - }, - ); - } - - Widget _buildRecipeCreate(BuildContext context, RecipeCreateStateLoaded state) { - List _options = state.autocompleteList.map((Product item) => item.name).toList(); - return Scaffold( - appBar: AppBar( - actions: [ - InkWell( - borderRadius: BorderRadius.circular(16), - child: Ink( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox(height: 4), - Text( - state.titleController.text, - style: TextStyle( - color: Colors.black, - fontSize: 14, - fontWeight: FontWeight.w400, - height: 1, - ), - ), - ], - ), - ), - ), - ], - ), - backgroundColor: Color.fromARGB(255, 240, 242, 245), - resizeToAvoidBottomInset: true, - body: SizedBox( - width: double.maxFinite, - child: SingleChildScrollView( - child: Column( - children: [ - Container( - padding: EdgeInsets.symmetric( - horizontal: 24, - vertical: 12, - ), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: const BorderRadius.all(Radius.circular(8)), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('Заголовок'), - SizedBox(height: 8), - CustomTextFormField( - fillColor: appTheme.gray50, - controller: state.titleController, - hintText: 'Заголовок', - ), - SizedBox(height: 16), - Text('Тип блюда'), - SizedBox(height: 8), - CustomDropDown( - value: state.selectedType, - items: state.types, - onChanged: changeType(context), - ), - SizedBox(height: 16), - Text('Изображение'), - GestureDetector( - onTap: () async { - final pickedFile = await state.picker.pickImage(source: ImageSource.gallery); - context.read().uploadRecipeImage(pickedFile); - }, - child: state.recipeImage == null - ? Container( - height: 128, - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadius.circular(16), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon( - Icons.photo_library, - color: appTheme.blueGray300, - ), - SizedBox(width: 8), - Text( - "Добавить фото", - selectionColor: appTheme.blueA400, - ), - ], - ), - ) - : Image.network( - baseUrl + '/storage/' + state.recipeImage!.path, - height: 150, - fit: BoxFit.cover, - ), - ), - SizedBox(height: 16), - Text('Время приготовления'), - SizedBox(height: 8), - CustomDropDown( - items: state.cookingTimes, - value: state.selectedCookingTime, - onChanged: changeCookingTime(context), - ), - SizedBox(height: 16), - Text('Статус'), - SizedBox(height: 8), - CustomDropDown( - items: state.statuses, - value: state.selectedStatus, - onChanged: changeStatus(context), - ), - SizedBox(height: 24), - if (!state.ingredients.isEmpty) - for (int j = 0; j < state.ingredients.length; j++) _buildIngredient(state.ingredients[j]), - SizedBox(height: 24), - RawAutocomplete( - optionsBuilder: _buildOptions(_options), - fieldViewBuilder: ( - BuildContext context, - TextEditingController productEditingController, - FocusNode focusNodeName, - VoidCallback onFieldSubmitted, - ) { - return CustomTextFormField( - hintText: 'Введите название продукта', - controller: TextEditingController(text: state.productNameController.text), - focusNode: focusNodeName, - onChanged: getAutocomplete(context, focusNodeName), - ); - }, - optionsViewBuilder: ( - BuildContext context, - AutocompleteOnSelected onSelected, - Iterable options, - ) { - return Align( - alignment: Alignment.topLeft, - child: Material( - elevation: 4.0, - child: SizedBox( - height: 200.0, - child: ListView.builder( - padding: const EdgeInsets.all(8.0), - itemCount: options.length, - itemBuilder: (BuildContext context, int index) { - final String option = options.elementAt(index); - return GestureDetector( - onTap: selectProduct(onSelected, option, state), - child: ListTile( - title: Text(option), - ), - ); - }, - ), - ), - ), - ); - }, - ), - SizedBox(height: 24), - CustomTextFormField( - hintText: 'Порция', - fillColor: appTheme.gray50, - controller: state.ingredientController, - keyboardType: TextInputType.number, - inputFormatters: [FilteringTextInputFormatter.digitsOnly], - ), - SizedBox(height: 8), - Row(children: [ - Text('гр'), - Switch( - value: state.ingredientAsItems, - onChanged: (bool value) => context.read().switchUnits(value), - activeColor: appTheme.blueA400, - inactiveThumbColor: Colors.grey, - inactiveTrackColor: Colors.grey.shade300, - ), - Text('шт'), - ],), - SizedBox(height: 8), - Container( - height: 48, - width: MediaQuery.of(context).size.width, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - backgroundColor: appTheme.blueA400, - ), - child: Text( - '+', - style: theme.textTheme.titleSmall, - ), - onPressed: () => context.read().addIngredient(new Ingredient( - name: state.productNameController.text, - portion: state.ingredientController.text, - unit: state.ingredientAsItems ? 'pcs' : 'gr',),),), - ), - SizedBox(height: 24), - Text('Описание рецепта'), - SizedBox(height: 8), - CustomTextFormField( - maxLines: 8, - minLines: 8, - controller: state.stepDescriptionController, - ), - SizedBox(height: 24), - for (int i = 0; i < state.numberOfSteps; i++) _buildStep(context, i, state), - SizedBox(height: 24), - Container( - height: 48, - width: MediaQuery.of(context).size.width, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - backgroundColor: appTheme.blueA400, - ), - child: Text( - '+', - style: theme.textTheme.titleSmall, - ), - onPressed: () => context.read().addStep(), - ), - ), - SizedBox(height: 8), - Container( - height: 48, - width: MediaQuery.of(context).size.width, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - backgroundColor: appTheme.blueA400, - ), - child: Text( - '-', - style: theme.textTheme.titleSmall, - ), - onPressed: () => context.read().removeStep(), - ), - ), - SizedBox(height: 24), - Text('Ссылка на видео (video)'), - SizedBox(height: 8), - CustomTextFormField( - hintText: 'Введите описание шага', - fillColor: appTheme.gray50, - controller: state.videoLinkController, - ), - SizedBox(height: 24), - Container( - height: 48, - width: MediaQuery.of(context).size.width, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - backgroundColor: appTheme.blueA400, - ), - child: Text( - 'Опубликовать', - style: theme.textTheme.titleSmall, - ), - onPressed: () => context.read().editRecipe(createRecipeFromState(state), recipeID), - ), - ), - ], - ),), - ], - ), - ), - ), - ); - } - - _buildStep(BuildContext context, int stepNumber, RecipeCreateStateLoaded state) { - return Column( - children: [ - Row(children: [Text('Шаг ${stepNumber + 1}'), Spacer(), Text('Всего шагов: ${state.numberOfSteps}')]), - SizedBox(height: 8), - GestureDetector( - onTap: () async { - final pickedFile = await state.picker.pickImage(source: ImageSource.gallery); - context.read().uploadStepImage(pickedFile, stepNumber); - }, - child: state.stepImages[stepNumber] == null - ? Container( - height: 128, - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadius.circular(16), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon( - Icons.photo_library, - color: appTheme.blueGray300, - ), - SizedBox(width: 8), - Text( - "Добавить фото", - selectionColor: appTheme.blueA400, - ), - SizedBox(height: 8), - ], - ), - ) - : Image.network( - baseUrl + '/storage/' + state.stepImages[stepNumber]!.path, - height: 150, - fit: BoxFit.cover, - ),), - SizedBox(height: 16), - CustomTextFormField( - hintText: 'Введите описание шага', - maxLines: 8, - minLines: 8, - fillColor: appTheme.gray50, - controller: state.stepControllers[stepNumber], - ), - SizedBox(height: 24), - ], - ); - } - - _buildIngredient(Ingredient ingredient) { - return Container( - margin: EdgeInsets.symmetric(horizontal: 12), - padding: EdgeInsets.symmetric( - horizontal: 8, - vertical: 8, - ), - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder5, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: EdgeInsets.only( - left: 8, - top: 8, - ), - child: Text( - ingredient.name.length > 8 ? ingredient.name.substring(0, 8) : ingredient.name, - style: CustomTextStyles.titleMedium16, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 24, - top: 4, - bottom: 4, - ), - child: Text( - ingredient.portion.toString() + ' ' + ingredient.unit.toString(), - ), - ), - Spacer(), - GestureDetector( - // onTap: removeIngredient(context, ingredient), - child: Padding( - padding: const EdgeInsets.only(right: 10), - child: Icon( - Icons.close, - color: appTheme.blueGray300, - ), - ), - ), - ], - ), - ); - } - - _buildOptions(List _options) { - return (TextEditingValue textEditingValue) { - return _options.where((String option) { - return true; - }); - }; - } - - selectProduct(AutocompleteOnSelected onSelected, String option, RecipeCreateStateLoaded state) { - state.productNameController.text = option; - return () { - onSelected(option); - }; - } - - getAutocomplete(BuildContext context, FocusNode focusNode) { - return (value) { - if (value.length > 2) { - context.read().inputProduct(value); - } - }; - } - - changeType(BuildContext context) { - return (value) { - context.read().changeType(value); - }; - } - - changeStatus(BuildContext context) { - return (value) { - context.read().changeStatus(value); - }; - } - - changeCookingTime(BuildContext context) { - return (value) { - context.read().changeCookingTime(value); - }; - } - - RecipeModel createRecipeFromState(RecipeCreateStateLoaded state) { - List ingredients = state.ingredients; - - List steps = []; - for (int i = 0; i < state.stepControllers.length; i++) { - if (state.stepControllers[i].text.isNotEmpty) { - steps.add(step.Step( - description: state.stepControllers[i].text, - image: state.stepImages[i]?.path, - ),); - } - } - - final RecipeModel recipe = RecipeModel( - ingredients: ingredients, - steps: steps, - state: state.selectedStatus.value, - type: state.selectedType.value, - cooking_time: state.selectedCookingTime.value, - description: state.stepDescriptionController.text, - title: state.titleController.text, - image: state.recipeImage?.path, - video_url: state.videoLinkController.text.isNotEmpty ? state.videoLinkController.text : null, - ); - return recipe; - } -} diff --git a/lib/features/recipes/presentation/widgets/info_about_recipe_widget.dart b/lib/features/recipes/presentation/widgets/info_about_recipe_widget.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/recipes/presentation/widgets/tags_widget.dart b/lib/features/recipes/presentation/widgets/tags_widget.dart new file mode 100644 index 00000000..e69de29b