feat(recipe): add creating recipes

This commit is contained in:
Alex
2024-12-18 11:56:20 +03:00
parent f6d4ea7df6
commit e0ec45e19e
24 changed files with 2267 additions and 510 deletions

View File

@@ -0,0 +1,219 @@
import 'dart:io';
import 'package:eatvio_app/features/recipes/entities/recipe_create_entity.dart';
import 'package:eatvio_app/features/recipes/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CreateRecipeCubit extends Cubit<CreateRecipeState> {
CreateRecipeCubit()
: super(
CreateRecipeState(
RecipeCreateEntity(
ingredients: [],
steps: [],
tags: [],
),
),
);
addStep() {
emit(
CreateRecipeState(
state.entity.copyWith(
steps: [
...state.entity.steps,
StepEntity(),
],
),
),
);
}
removeStep(StepEntity step) {
List<StepEntity> steps = [...state.entity.steps];
steps.remove(step);
emit(
CreateRecipeState(state.entity.copyWith(steps: steps)),
);
}
addIngredient(IngredientEntity entity) {
emit(
CreateRecipeState(
state.entity.copyWith(
ingredients: [
...state.entity.ingredients,
entity,
],
),
),
);
}
removeIngredient(int index) {
List<IngredientEntity> ingredients = [...state.entity.ingredients];
ingredients.removeAt(index);
emit(
CreateRecipeState(
state.entity.copyWith(
ingredients: ingredients,
),
),
);
}
replaceIngredientPosition(int oldIndex, int newIndex) {
List<IngredientEntity> ingredients = [...state.entity.ingredients];
final IngredientEntity item = ingredients.removeAt(oldIndex);
ingredients.insert(newIndex, item);
emit(
CreateRecipeState(
state.entity.copyWith(
ingredients: ingredients,
),
),
);
}
replaceTitle(String title) {
emit(
CreateRecipeState(
state.entity.copyWith(
title: title,
),
),
);
}
replaceDescription(String description) {
emit(
CreateRecipeState(
state.entity.copyWith(
description: description,
),
),
);
}
changeType(TypeOfRecipe typeOfRecipe) {
emit(
CreateRecipeState(
state.entity.copyWith(
typeOfRecipe: typeOfRecipe,
),
),
);
}
addTag(String tag) {
emit(
CreateRecipeState(
state.entity.copyWith(
tags: [
...state.entity.tags,
tag,
],
),
),
);
}
removeTag(String tag) {
List<String> tags = [...state.entity.tags];
tags.remove(tag);
emit(
CreateRecipeState(
state.entity.copyWith(
tags: tags,
),
),
);
}
replacePortionsCount(int count) {
emit(
CreateRecipeState(
state.entity.copyWith(
countOfPortions: count,
),
),
);
}
replaceEnegryInPortion(double energy) {
emit(
CreateRecipeState(
state.entity.copyWith(
energyInOnePortion: energy,
),
),
);
}
replaceTotalTime(String time) {
emit(
CreateRecipeState(
state.entity.copyWith(
totalCookTime: time,
),
),
);
}
replaceActiveTime(String time) {
emit(
CreateRecipeState(
state.entity.copyWith(
activeCookTime: time,
),
),
);
}
replaceVideoUrl(String videoUrl) {
emit(
CreateRecipeState(
state.entity.copyWith(
videoUrl: videoUrl,
),
),
);
}
replaceImage(File? image) {
emit(
CreateRecipeState(
state.entity.copyWith(
image: image,
),
),
);
}
replaceDescriptionInStep(String description, int index) {
List<StepEntity> steps = [...state.entity.steps];
steps[index] = steps[index].copyWith(description: description);
emit(
CreateRecipeState(
state.entity.copyWith(
steps: steps,
),
),
);
}
replaceImageInStep(File? image, int index) {
List<StepEntity> steps = [...state.entity.steps];
steps[index] = steps[index].copyWith(image: image);
emit(
CreateRecipeState(
state.entity.copyWith(
steps: steps,
),
),
);
}
}

View File

@@ -0,0 +1,11 @@
import 'package:eatvio_app/features/recipes/entities/recipe_create_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'create_recipe_state.freezed.dart';
@freezed
class CreateRecipeState with _$CreateRecipeState {
const factory CreateRecipeState(
RecipeCreateEntity entity,
) = _CreateRecipeState;
}

View File

@@ -0,0 +1,160 @@
// 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 'create_recipe_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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 _$CreateRecipeState {
RecipeCreateEntity get entity => throw _privateConstructorUsedError;
/// Create a copy of CreateRecipeState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CreateRecipeStateCopyWith<CreateRecipeState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CreateRecipeStateCopyWith<$Res> {
factory $CreateRecipeStateCopyWith(
CreateRecipeState value, $Res Function(CreateRecipeState) then) =
_$CreateRecipeStateCopyWithImpl<$Res, CreateRecipeState>;
@useResult
$Res call({RecipeCreateEntity entity});
$RecipeCreateEntityCopyWith<$Res> get entity;
}
/// @nodoc
class _$CreateRecipeStateCopyWithImpl<$Res, $Val extends CreateRecipeState>
implements $CreateRecipeStateCopyWith<$Res> {
_$CreateRecipeStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CreateRecipeState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? entity = null,
}) {
return _then(_value.copyWith(
entity: null == entity
? _value.entity
: entity // ignore: cast_nullable_to_non_nullable
as RecipeCreateEntity,
) as $Val);
}
/// Create a copy of CreateRecipeState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$RecipeCreateEntityCopyWith<$Res> get entity {
return $RecipeCreateEntityCopyWith<$Res>(_value.entity, (value) {
return _then(_value.copyWith(entity: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$CreateRecipeStateImplCopyWith<$Res>
implements $CreateRecipeStateCopyWith<$Res> {
factory _$$CreateRecipeStateImplCopyWith(_$CreateRecipeStateImpl value,
$Res Function(_$CreateRecipeStateImpl) then) =
__$$CreateRecipeStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({RecipeCreateEntity entity});
@override
$RecipeCreateEntityCopyWith<$Res> get entity;
}
/// @nodoc
class __$$CreateRecipeStateImplCopyWithImpl<$Res>
extends _$CreateRecipeStateCopyWithImpl<$Res, _$CreateRecipeStateImpl>
implements _$$CreateRecipeStateImplCopyWith<$Res> {
__$$CreateRecipeStateImplCopyWithImpl(_$CreateRecipeStateImpl _value,
$Res Function(_$CreateRecipeStateImpl) _then)
: super(_value, _then);
/// Create a copy of CreateRecipeState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? entity = null,
}) {
return _then(_$CreateRecipeStateImpl(
null == entity
? _value.entity
: entity // ignore: cast_nullable_to_non_nullable
as RecipeCreateEntity,
));
}
}
/// @nodoc
class _$CreateRecipeStateImpl implements _CreateRecipeState {
const _$CreateRecipeStateImpl(this.entity);
@override
final RecipeCreateEntity entity;
@override
String toString() {
return 'CreateRecipeState(entity: $entity)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CreateRecipeStateImpl &&
(identical(other.entity, entity) || other.entity == entity));
}
@override
int get hashCode => Object.hash(runtimeType, entity);
/// Create a copy of CreateRecipeState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CreateRecipeStateImplCopyWith<_$CreateRecipeStateImpl> get copyWith =>
__$$CreateRecipeStateImplCopyWithImpl<_$CreateRecipeStateImpl>(
this, _$identity);
}
abstract class _CreateRecipeState implements CreateRecipeState {
const factory _CreateRecipeState(final RecipeCreateEntity entity) =
_$CreateRecipeStateImpl;
@override
RecipeCreateEntity get entity;
/// Create a copy of CreateRecipeState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CreateRecipeStateImplCopyWith<_$CreateRecipeStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}