my diets have been update

This commit is contained in:
Username1548
2025-02-17 14:40:31 +07:00
parent 070d7e1047
commit 291947bd32
98 changed files with 4969 additions and 2670 deletions

View File

@@ -0,0 +1,242 @@
import 'dart:developer';
import 'dart:io';
import 'package:eatvio_app/features/create_recipe/entities/recipe_create_entity.dart';
import 'package:eatvio_app/features/create_recipe/models/ingredient.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:eatvio_app/features/create_recipe/reporitories/recipe_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CreateRecipeCubit extends Cubit<CreateRecipeState> {
final RecipeRepository recipeRepository;
CreateRecipeCubit({required this.recipeRepository})
: super(
CreateRecipeState(
entity: RecipeCreateEntity(
typeOfRecipe: TypeOfRecipe.first_meals,
ingredients: [],
steps: [StepEntity()],
tags: [],
),
),
);
addStep() {
emit(
state.copyWith.entity(
steps: [
...state.entity.steps,
StepEntity(),
],
),
);
}
removeStep(StepEntity step) {
List<StepEntity> steps = [...state.entity.steps];
steps.remove(step);
emit(state.copyWith.entity(steps: steps));
}
addIngredient(Ingredient entity) {
emit(
state.copyWith.entity(
ingredients: [
...state.entity.ingredients,
entity,
],
),
);
}
removeIngredient(int index) {
List<Ingredient> ingredients = [...state.entity.ingredients];
ingredients.removeAt(index);
emit(state.copyWith.entity(ingredients: ingredients));
}
replaceIngredientPosition(int oldIndex, int newIndex) {
List<Ingredient> ingredients = [...state.entity.ingredients];
final item = ingredients.removeAt(oldIndex);
ingredients.insert(newIndex, item);
emit(state.copyWith.entity(ingredients: ingredients));
}
replaceTitle(String title) {
emit(state.copyWith.entity(title: title == '' ? null : title));
}
replaceDescription(String description) {
emit(state.copyWith.entity(description: description == '' ? null : description));
}
changeType(TypeOfRecipe typeOfRecipe) {
emit(state.copyWith.entity(typeOfRecipe: typeOfRecipe));
}
addTag(String tag) {
emit(
state.copyWith.entity(
tags: [
...state.entity.tags,
tag,
],
),
);
}
removeTag(String tag) {
List<String> tags = [...state.entity.tags];
tags.remove(tag);
emit(state.copyWith.entity(tags: tags));
}
replacePortionsCount(int count) {
emit(state.copyWith.entity(countOfPortions: count));
}
replaceEnegryInPortion(double energy) {
emit(state.copyWith.entity(energyInOnePortion: energy));
}
setTotalCookingMinutes(int minutes) {
emit(state.copyWith.entity(totalCookMinutes: minutes));
}
setTotalCookingHours(int hours) {
emit(state.copyWith.entity(totalCookHours: hours));
}
setActiveCookingMinutes(int minutes) {
emit(state.copyWith.entity(activeCookMinutes: minutes));
}
setActiveCookingHours(int hours) {
emit(state.copyWith.entity(activeCookHours: hours));
}
replaceVideoUrl(String videoUrl) {
emit(state.copyWith.entity(videoUrl: videoUrl));
}
replaceImage(File? image) {
emit(state.copyWith.entity(image: image));
}
replaceDescriptionInStep(String description, int index) {
List<StepEntity> steps = [...state.entity.steps];
steps[index] = steps[index].copyWith(description: description);
emit(state.copyWith.entity(steps: steps));
}
replaceImageInStep(File? image, int index) {
List<StepEntity> steps = [...state.entity.steps];
steps[index] = steps[index].copyWith(image: image);
emit(state.copyWith.entity(steps: steps));
}
Future<bool> publishRecipe() async {
try {
final model = state.entity.toModel();
await recipeRepository.publishRecipe(model);
return true;
} catch (e, st) {
log(e.toString(), stackTrace: st);
return false;
}
}
bool validateAll() {
final isTitleValid = validateTitle();
final isDescValid = validateDescription();
final isImageValid = validateImage();
final areServingsValid = validateServings();
final isCookTimeValid = validateTotalCookTime();
final isActiveCookTimeValid = validateActiveCookTime();
final isEnergyPerServingsValid = validateEnergyPerServing();
return isTitleValid && isDescValid && isImageValid && areServingsValid && isCookTimeValid && isActiveCookTimeValid && isEnergyPerServingsValid;
}
bool validateTitle() {
if (state.entity.title == null || (state.entity.title?.isEmpty ?? true)) {
emit(state.copyWith(titleValidationError: 'Поле не заполнено'));
return false;
} else if (state.entity.title!.length < 3) {
emit(state.copyWith(titleValidationError: 'Минимальная длина 3 символа '));
return false;
} else {
emit(state.copyWith(titleValidationError: null));
return true;
}
}
bool validateServings() {
if (state.entity.countOfPortions == null) {
emit(state.copyWith(servingsValidationError: 'Поле не заполнено'));
return false;
} else {
emit(state.copyWith(servingsValidationError: null));
return true;
}
}
bool validateEnergyPerServing() {
if (state.entity.energyInOnePortion == null) {
emit(state.copyWith(energyPerServingValidationError: 'Поле не заполнено'));
return false;
} else {
emit(state.copyWith(energyPerServingValidationError: null));
return true;
}
}
bool validateActiveCookTime() {
if (state.entity.activeCookHours == null && state.entity.activeCookMinutes == null) {
emit(state.copyWith(activeTimeValidationError: 'Поле не заполнено'));
return false;
} else {
emit(state.copyWith(activeTimeValidationError: null));
return true;
}
}
bool validateTotalCookTime() {
if (state.entity.totalCookHours == null || state.entity.totalCookMinutes == null) {
emit(state.copyWith(cookingTimeValidationError: 'Поле не заполнено'));
return false;
} else {
emit(state.copyWith(cookingTimeValidationError: null));
return true;
}
}
bool validateDescription() {
if (state.entity.description == null || (state.entity.description?.isEmpty ?? true)) {
emit(state.copyWith(descriptionValidationError: 'Поле не заполнено'));
return false;
} else if (state.entity.description!.length < 3) {
emit(state.copyWith(descriptionValidationError: 'Минимальная длина 3 символа '));
return false;
} else {
emit(state.copyWith(descriptionValidationError: null));
return true;
}
}
bool validateImage() {
if (state.entity.image == null) {
emit(state.copyWith(imageValidationError: 'Поле не заполнено'));
return false;
} else {
emit(state.copyWith(imageValidationError: null));
return true;
}
}
}

View File

@@ -0,0 +1,19 @@
import 'package:eatvio_app/features/create_recipe/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({
required RecipeCreateEntity entity,
String? titleValidationError,
String? descriptionValidationError,
String? cookingTimeValidationError,
String? activeTimeValidationError,
String? servingsValidationError,
String? energyPerServingValidationError,
String? imageValidationError,
}) = _CreateRecipeState;
}

View File

@@ -0,0 +1,330 @@
// 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;
String? get titleValidationError => throw _privateConstructorUsedError;
String? get descriptionValidationError => throw _privateConstructorUsedError;
String? get cookingTimeValidationError => throw _privateConstructorUsedError;
String? get activeTimeValidationError => throw _privateConstructorUsedError;
String? get servingsValidationError => throw _privateConstructorUsedError;
String? get energyPerServingValidationError =>
throw _privateConstructorUsedError;
String? get imageValidationError => 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,
String? titleValidationError,
String? descriptionValidationError,
String? cookingTimeValidationError,
String? activeTimeValidationError,
String? servingsValidationError,
String? energyPerServingValidationError,
String? imageValidationError});
$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,
Object? titleValidationError = freezed,
Object? descriptionValidationError = freezed,
Object? cookingTimeValidationError = freezed,
Object? activeTimeValidationError = freezed,
Object? servingsValidationError = freezed,
Object? energyPerServingValidationError = freezed,
Object? imageValidationError = freezed,
}) {
return _then(_value.copyWith(
entity: null == entity
? _value.entity
: entity // ignore: cast_nullable_to_non_nullable
as RecipeCreateEntity,
titleValidationError: freezed == titleValidationError
? _value.titleValidationError
: titleValidationError // ignore: cast_nullable_to_non_nullable
as String?,
descriptionValidationError: freezed == descriptionValidationError
? _value.descriptionValidationError
: descriptionValidationError // ignore: cast_nullable_to_non_nullable
as String?,
cookingTimeValidationError: freezed == cookingTimeValidationError
? _value.cookingTimeValidationError
: cookingTimeValidationError // ignore: cast_nullable_to_non_nullable
as String?,
activeTimeValidationError: freezed == activeTimeValidationError
? _value.activeTimeValidationError
: activeTimeValidationError // ignore: cast_nullable_to_non_nullable
as String?,
servingsValidationError: freezed == servingsValidationError
? _value.servingsValidationError
: servingsValidationError // ignore: cast_nullable_to_non_nullable
as String?,
energyPerServingValidationError: freezed ==
energyPerServingValidationError
? _value.energyPerServingValidationError
: energyPerServingValidationError // ignore: cast_nullable_to_non_nullable
as String?,
imageValidationError: freezed == imageValidationError
? _value.imageValidationError
: imageValidationError // ignore: cast_nullable_to_non_nullable
as String?,
) 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,
String? titleValidationError,
String? descriptionValidationError,
String? cookingTimeValidationError,
String? activeTimeValidationError,
String? servingsValidationError,
String? energyPerServingValidationError,
String? imageValidationError});
@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,
Object? titleValidationError = freezed,
Object? descriptionValidationError = freezed,
Object? cookingTimeValidationError = freezed,
Object? activeTimeValidationError = freezed,
Object? servingsValidationError = freezed,
Object? energyPerServingValidationError = freezed,
Object? imageValidationError = freezed,
}) {
return _then(_$CreateRecipeStateImpl(
entity: null == entity
? _value.entity
: entity // ignore: cast_nullable_to_non_nullable
as RecipeCreateEntity,
titleValidationError: freezed == titleValidationError
? _value.titleValidationError
: titleValidationError // ignore: cast_nullable_to_non_nullable
as String?,
descriptionValidationError: freezed == descriptionValidationError
? _value.descriptionValidationError
: descriptionValidationError // ignore: cast_nullable_to_non_nullable
as String?,
cookingTimeValidationError: freezed == cookingTimeValidationError
? _value.cookingTimeValidationError
: cookingTimeValidationError // ignore: cast_nullable_to_non_nullable
as String?,
activeTimeValidationError: freezed == activeTimeValidationError
? _value.activeTimeValidationError
: activeTimeValidationError // ignore: cast_nullable_to_non_nullable
as String?,
servingsValidationError: freezed == servingsValidationError
? _value.servingsValidationError
: servingsValidationError // ignore: cast_nullable_to_non_nullable
as String?,
energyPerServingValidationError: freezed ==
energyPerServingValidationError
? _value.energyPerServingValidationError
: energyPerServingValidationError // ignore: cast_nullable_to_non_nullable
as String?,
imageValidationError: freezed == imageValidationError
? _value.imageValidationError
: imageValidationError // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
class _$CreateRecipeStateImpl implements _CreateRecipeState {
const _$CreateRecipeStateImpl(
{required this.entity,
this.titleValidationError,
this.descriptionValidationError,
this.cookingTimeValidationError,
this.activeTimeValidationError,
this.servingsValidationError,
this.energyPerServingValidationError,
this.imageValidationError});
@override
final RecipeCreateEntity entity;
@override
final String? titleValidationError;
@override
final String? descriptionValidationError;
@override
final String? cookingTimeValidationError;
@override
final String? activeTimeValidationError;
@override
final String? servingsValidationError;
@override
final String? energyPerServingValidationError;
@override
final String? imageValidationError;
@override
String toString() {
return 'CreateRecipeState(entity: $entity, titleValidationError: $titleValidationError, descriptionValidationError: $descriptionValidationError, cookingTimeValidationError: $cookingTimeValidationError, activeTimeValidationError: $activeTimeValidationError, servingsValidationError: $servingsValidationError, energyPerServingValidationError: $energyPerServingValidationError, imageValidationError: $imageValidationError)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CreateRecipeStateImpl &&
(identical(other.entity, entity) || other.entity == entity) &&
(identical(other.titleValidationError, titleValidationError) ||
other.titleValidationError == titleValidationError) &&
(identical(other.descriptionValidationError,
descriptionValidationError) ||
other.descriptionValidationError ==
descriptionValidationError) &&
(identical(other.cookingTimeValidationError,
cookingTimeValidationError) ||
other.cookingTimeValidationError ==
cookingTimeValidationError) &&
(identical(other.activeTimeValidationError,
activeTimeValidationError) ||
other.activeTimeValidationError == activeTimeValidationError) &&
(identical(
other.servingsValidationError, servingsValidationError) ||
other.servingsValidationError == servingsValidationError) &&
(identical(other.energyPerServingValidationError,
energyPerServingValidationError) ||
other.energyPerServingValidationError ==
energyPerServingValidationError) &&
(identical(other.imageValidationError, imageValidationError) ||
other.imageValidationError == imageValidationError));
}
@override
int get hashCode => Object.hash(
runtimeType,
entity,
titleValidationError,
descriptionValidationError,
cookingTimeValidationError,
activeTimeValidationError,
servingsValidationError,
energyPerServingValidationError,
imageValidationError);
/// 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(
{required final RecipeCreateEntity entity,
final String? titleValidationError,
final String? descriptionValidationError,
final String? cookingTimeValidationError,
final String? activeTimeValidationError,
final String? servingsValidationError,
final String? energyPerServingValidationError,
final String? imageValidationError}) = _$CreateRecipeStateImpl;
@override
RecipeCreateEntity get entity;
@override
String? get titleValidationError;
@override
String? get descriptionValidationError;
@override
String? get cookingTimeValidationError;
@override
String? get activeTimeValidationError;
@override
String? get servingsValidationError;
@override
String? get energyPerServingValidationError;
@override
String? get imageValidationError;
/// 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;
}

View File

@@ -0,0 +1,94 @@
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/utils/toasts.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/info_about_recipe_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/ingredients_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/steps_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class RecipeCreateScreen extends StatefulWidget {
const RecipeCreateScreen({super.key});
static const name = 'recipeCreateScreen';
static const path = '/recipe-create-screen';
@override
State<RecipeCreateScreen> createState() => _RecipeCreateScreenState();
}
class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
@override
Widget build(BuildContext context) {
return BlocProvider<CreateRecipeCubit>(
create: (BuildContext context) => sl<CreateRecipeCubit>(),
child: Scaffold(
backgroundColor: Color(0xFFF0F2F5),
appBar: AppBar(
title: Text('Добавление рецепта'),
centerTitle: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(12),
),
),
),
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: EdgeInsets.only(top: 8, bottom: 32),
child: Column(
spacing: 16,
children: [
InfoAboutRecipeWidget(),
IngredientsWidget(),
StepsWidget(),
BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
builder: (context, state) {
return Builder(
builder: (context) {
return InkWell(
onTap: () async {
if (context.read<CreateRecipeCubit>().validateAll()) {
final isSuccess = await context.read<CreateRecipeCubit>().publishRecipe();
if (isSuccess) {
showSuccessToast('Рецепт успешно опубликован');
Navigator.pop(context);
} else {
showErrorToast('Не удалось опубликовать рецепт');
}
}
},
borderRadius: BorderRadius.circular(20),
child: Ink(
width: MediaQuery.of(context).size.width - 32,
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: BorderRadius.circular(20),
),
child: Container(
padding: const EdgeInsets.all(16),
alignment: Alignment.center,
child: Text(
'Опубликовать',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
),
),
);
},
);
},
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,119 @@
import 'dart:io';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:image_picker/image_picker.dart';
class ImageWidget extends StatefulWidget {
const ImageWidget({super.key, required this.image});
final File? image;
@override
State<ImageWidget> createState() => _ImageWidgetState();
}
class _ImageWidgetState extends State<ImageWidget> {
late final CreateRecipeCubit createRecipeCubit;
@override
void initState() {
super.initState();
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
_showImagePicker();
},
child: widget.image == null
? SvgPicture.asset(
width: MediaQuery.of(context).size.width - 32,
'assets/icons/upload_photo_of_portion.svg',
)
: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.file(
File(widget.image!.path),
),
),
Positioned(
right: 16,
top: 16,
child: GestureDetector(
onTap: () {
createRecipeCubit.replaceImage(null);
},
child: Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: Icon(Icons.close_rounded),
),
),
),
],
),
);
}
_showImagePicker() {
showCupertinoModalPopup<void>(
context: context,
builder: (context) => CupertinoActionSheet(
actions: [
CupertinoActionSheetAction(
onPressed: () async {
final picker = ImagePicker();
final image = await picker.pickImage(source: ImageSource.camera);
setState(() {});
if (image != null) {
createRecipeCubit.replaceImage(File(image.path));
createRecipeCubit.validateImage();
}
Navigator.of(context).pop();
},
child: const Row(
children: const [
Icon(Icons.photo_camera),
SizedBox(width: 8),
Text('Фото'),
],
),
),
CupertinoActionSheetAction(
onPressed: () async {
final picker = ImagePicker();
final image = await picker.pickImage(source: ImageSource.gallery);
setState(() {});
if (image != null) {
createRecipeCubit.replaceImage(File(image.path));
createRecipeCubit.validateImage();
}
Navigator.of(context).pop();
},
child: const Row(
children: const [
Icon(Icons.photo),
SizedBox(width: 8),
Text('Галерея'),
],
),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.of(context).pop(),
isDestructiveAction: true,
child: const Text('Отмена'),
),
),
);
}
}

View File

@@ -0,0 +1,160 @@
import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_drop_down.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:eatvio_app/features/create_recipe/entities/recipe_create_entity.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/image_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/portion_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/tags_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/time_of_cook_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class InfoAboutRecipeWidget extends StatefulWidget {
const InfoAboutRecipeWidget({super.key});
@override
State<InfoAboutRecipeWidget> createState() => _InfoAboutRecipeWidgetState();
}
class _InfoAboutRecipeWidgetState extends State<InfoAboutRecipeWidget> {
final List<SelectionPopupModel> items = TypeOfRecipe.values.map((e) => SelectionPopupModel(title: e.toString())).toList();
late SelectionPopupModel selectedType;
late final CreateRecipeCubit createRecipeCubit;
@override
void initState() {
super.initState();
selectedType = items.first;
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return Material(
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Название'),
SizedBox(height: 4),
BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
buildWhen: (previous, current) => previous.titleValidationError != current.titleValidationError,
builder: (context, state) {
return Column(
children: [
CustomTextFormField(
hintText: 'Например: тар-тар из говядины',
hasError: state.titleValidationError != null,
onChanged: (value) {
createRecipeCubit.replaceTitle(value);
if (state.titleValidationError != null) {
createRecipeCubit.validateTitle();
}
},
),
if (state.titleValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.titleValidationError!,
),
],
],
);
},
),
const SizedBox(height: 12),
Text('Тип блюда'),
SizedBox(height: 4),
CustomDropDown(
items: items,
value: selectedType,
onChanged: (newSelectedType) {
setState(() {
selectedType = newSelectedType;
});
createRecipeCubit.changeType(
TypeOfRecipe.fromString(selectedType.title) ?? TypeOfRecipe.other,
);
},
),
const SizedBox(height: 12),
TagsWidget(),
const SizedBox(height: 12),
PortionWidget(),
const SizedBox(height: 12),
TimeOfCookWidget(),
const SizedBox(height: 12),
Text('Описание'),
SizedBox(height: 4),
BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
buildWhen: (previous, current) => previous.descriptionValidationError != current.descriptionValidationError,
builder: (context, state) {
return Column(
children: [
CustomTextFormField(
hintText: 'Расскажите, почему вы выбрали именно этот рецепт? Опишите, каким будет готовое блюдо и в чём его достоинства.',
minLines: 5,
maxLines: 5,
hasError: state.descriptionValidationError != null,
onChanged: (value) {
createRecipeCubit.replaceDescription(value);
if (state.descriptionValidationError != null) {
createRecipeCubit.validateDescription();
}
},
),
if (state.descriptionValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.descriptionValidationError!,
),
],
],
);
},
),
const SizedBox(height: 12),
Text('Фото обложка'),
SizedBox(height: 4),
BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
buildWhen: (previous, current) => previous.imageValidationError != current.imageValidationError || previous.entity.image != current.entity.image,
builder: (context, state) {
return Column(
children: [
Container(
child: ImageWidget(image: state.entity.image),
decoration: state.imageValidationError != null
? BoxDecoration(border: Border.all(width: 1, color: appTheme.red), borderRadius: BorderRadius.circular(8))
: null,
),
if (state.imageValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.imageValidationError!,
),
],
],
);
},
),
const SizedBox(height: 12),
Text('Ссылка на видео (если есть)'),
SizedBox(height: 4),
CustomTextFormField(
hintText: 'Прикрепите ссылку на видео',
onChanged: (value) {
createRecipeCubit.replaceVideoUrl(value);
},
),
],
),
),
);
}
}

View File

@@ -0,0 +1,223 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_recipe/models/ingredient.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class IngredientsWidget extends StatefulWidget {
const IngredientsWidget({super.key});
@override
State<IngredientsWidget> createState() => _IngredientsWidgetState();
}
class _IngredientsWidgetState extends State<IngredientsWidget> {
late final CreateRecipeCubit createRecipeCubit;
final nameController = TextEditingController();
final gramsController = TextEditingController();
final pcsController = TextEditingController();
@override
void initState() {
super.initState();
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
builder: (BuildContext context, CreateRecipeState state) {
return Material(
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Ингредиенты ',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Color(0xFF323F4B),
),
),
),
ReorderableListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
onReorder: (int oldIndex, int newIndex) {
setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
});
createRecipeCubit.replaceIngredientPosition(oldIndex, newIndex);
},
children: <Widget>[
for (int index = 0; index < state.entity.ingredients.length; index += 1)
ListTile(
contentPadding: EdgeInsets.symmetric(horizontal: 16),
key: Key('$index'),
leading: Icon(
Icons.drag_handle_rounded,
color: Colors.grey.shade600,
),
title: Text(state.entity.ingredients[index].name),
subtitle: Text('${state.entity.ingredients[index].portion} ${state.entity.ingredients[index].unit == 'gr' ? 'гр' : 'шт'}'),
trailing: IconButton(
onPressed: () {
createRecipeCubit.removeIngredient(index);
},
icon: Icon(
Icons.delete_outline_rounded,
color: Colors.grey.shade600,
),
),
),
],
),
ListTile(
onTap: () {
nameController.clear();
gramsController.clear();
pcsController.clear();
showModalBottomSheet(
useRootNavigator: true,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
),
isScrollControlled: true,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setStateInner) {
return Padding(
padding: const EdgeInsets.all(16) +
EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Добавление ингредиента',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Color(0xFF323F4B),
),
),
const SizedBox(height: 16),
SizedBox(
width: MediaQuery.of(context).size.width - 32,
child: CustomTextFormField(
autofocus: true,
controller: nameController,
hintText: 'Введите название продукта',
onChanged: (query) {},
),
),
const SizedBox(height: 8),
Row(
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 2 - 20,
child: CustomTextFormField(
enabled: pcsController.text.isEmpty ? true : false,
keyboardType: TextInputType.number,
controller: gramsController,
hintText: pcsController.text.isEmpty ? '100' : null,
suffixText: 'гр',
onChanged: (value) {
setStateInner(() {});
},
),
),
const SizedBox(width: 8),
SizedBox(
width: MediaQuery.of(context).size.width / 2 - 20,
child: CustomTextFormField(
enabled: gramsController.text.isEmpty ? true : false,
keyboardType: TextInputType.number,
controller: pcsController,
onChanged: (value) {
setStateInner(() {});
},
hintText: gramsController.text.isEmpty ? '1' : null,
suffixText: 'шт',
),
),
],
),
const SizedBox(height: 12),
InkWell(
onTap: () {
if (nameController.text.isNotEmpty && (pcsController.text.isNotEmpty || gramsController.text.isNotEmpty)) {
createRecipeCubit.addIngredient(
Ingredient(
name: nameController.text,
unit: gramsController.text.isEmpty ? 'pcs' : 'gr',
portion: gramsController.text.isEmpty ? pcsController.text : gramsController.text,
),
);
Navigator.of(context).pop();
setState(() {});
}
},
borderRadius: BorderRadius.circular(20),
child: Ink(
width: MediaQuery.of(context).size.width - 32,
height: 52,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: appTheme.blueA400,
),
child: Center(
child: Text(
'Добавить',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
),
),
],
),
);
},
);
},
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
title: Text(
'Добавить ингредиент',
style: TextStyle(
color: appTheme.blueA400,
),
),
leading: Icon(
Icons.add_rounded,
color: appTheme.blueA400,
),
),
],
),
),
);
},
);
}
}

View File

@@ -0,0 +1,107 @@
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class PortionWidget extends StatefulWidget {
const PortionWidget({super.key});
@override
State<PortionWidget> createState() => _PortionWidgetState();
}
class _PortionWidgetState extends State<PortionWidget> {
late final CreateRecipeCubit createRecipeCubit;
@override
void initState() {
super.initState();
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
buildWhen: (previous, current) =>
previous.servingsValidationError != current.servingsValidationError ||
previous.energyPerServingValidationError != current.energyPerServingValidationError,
builder: (context, state) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Кол-во порций'),
SizedBox(height: 4),
Column(
children: [
CustomTextFormField(
hintText: '1',
hasError: state.servingsValidationError != null,
textInputType: TextInputType.number,
onChanged: (value) {
createRecipeCubit.replacePortionsCount(int.parse(value));
if (state.servingsValidationError != null) {
createRecipeCubit.validateServings();
}
},
),
if (state.servingsValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.servingsValidationError!,
),
],
],
),
],
),
),
const SizedBox(width: 8),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Ккал в одной порции'),
SizedBox(height: 4),
Column(
children: [
CustomTextFormField(
hintText: '100',
hasError: state.energyPerServingValidationError != null,
suffixText: 'Ккал',
textInputType: TextInputType.numberWithOptions(decimal: true),
onChanged: (value) {
createRecipeCubit.replaceEnegryInPortion(double.parse(value));
if (state.energyPerServingValidationError != null) {
createRecipeCubit.validateEnergyPerServing();
}
},
),
if (state.energyPerServingValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.energyPerServingValidationError!,
),
],
],
),
],
),
),
],
),
],
);
},
);
}
}

View File

@@ -0,0 +1,126 @@
import 'dart:io';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:image_picker/image_picker.dart';
class StepImageWidget extends StatefulWidget {
final int index;
const StepImageWidget({
super.key,
required this.index,
});
@override
State<StepImageWidget> createState() => _StepImageWidgetState();
}
class _StepImageWidgetState extends State<StepImageWidget> {
XFile? image;
late final CreateRecipeCubit createRecipeCubit;
@override
void initState() {
super.initState();
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
_showImagePicker();
},
child: image == null
? SvgPicture.asset(
width: MediaQuery.of(context).size.width - 32,
'assets/icons/add_step_photo.svg',
)
: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.file(
File(image!.path),
),
),
Positioned(
right: 16,
top: 16,
child: GestureDetector(
onTap: () {
setState(() {
image = null;
});
createRecipeCubit.replaceImageInStep(null, widget.index);
},
child: Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: Icon(Icons.close_rounded),
),
),
),
],
),
);
}
_showImagePicker() {
showCupertinoModalPopup<void>(
context: context,
builder: (context) => CupertinoActionSheet(
actions: [
CupertinoActionSheetAction(
onPressed: () async {
final picker = ImagePicker();
image = await picker.pickImage(source: ImageSource.camera);
setState(() {});
if (image != null) {
createRecipeCubit.replaceImageInStep(File(image!.path), widget.index);
}
Navigator.of(context).pop();
},
child: const Row(
children: const [
Icon(Icons.photo_camera),
SizedBox(width: 8),
Text('Фото'),
],
),
),
CupertinoActionSheetAction(
onPressed: () async {
final picker = ImagePicker();
image = await picker.pickImage(source: ImageSource.gallery);
setState(() {});
if (image != null) {
createRecipeCubit.replaceImageInStep(File(image!.path), widget.index);
}
Navigator.of(context).pop();
},
child: const Row(
children: const [
Icon(Icons.photo),
SizedBox(width: 8),
Text('Галерея'),
],
),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.of(context).pop(),
isDestructiveAction: true,
child: const Text('Отмена'),
),
),
);
}
}

View File

@@ -0,0 +1,135 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:eatvio_app/features/create_recipe/presentation/widgets/step_image_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class StepsWidget extends StatefulWidget {
const StepsWidget({super.key});
@override
State<StepsWidget> createState() => _StepsWidgetState();
}
class _StepsWidgetState extends State<StepsWidget> {
late final CreateRecipeCubit createRecipeCubit;
@override
void initState() {
super.initState();
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
builder: (BuildContext context, CreateRecipeState state) {
return Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Пошаговая инструкция',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Color(0xFF323F4B),
),
),
const SizedBox(height: 12),
ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: BorderRadius.circular(8),
),
child: Text(
'Шаг ${index + 1}',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
),
GestureDetector(
onTap: () {
context.read<CreateRecipeCubit>().removeStep(state.entity.steps[index]);
},
child: Icon(Icons.delete_outline_rounded),
),
],
),
const SizedBox(height: 12),
Text('Описание'),
SizedBox(height: 4),
CustomTextFormField(
hintText: 'Например: подготовьте ингредиенты',
maxLines: 5,
minLines: 3,
onChanged: (value) {
createRecipeCubit.replaceDescriptionInStep(value, index);
},
),
const SizedBox(height: 12),
Text('Фото шага'),
SizedBox(height: 4),
StepImageWidget(
index: index,
),
],
),
itemCount: state.entity.steps.length,
separatorBuilder: (BuildContext context, int index) => const SizedBox(height: 24),
),
InkWell(
onTap: () {
context.read<CreateRecipeCubit>().addStep();
},
borderRadius: BorderRadius.circular(20),
child: Ink(
width: MediaQuery.of(context).size.width - 32,
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: BorderRadius.circular(20),
),
child: Container(
padding: const EdgeInsets.all(16),
alignment: Alignment.center,
child: Text(
'Добавить шаг',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
),
),
),
],
),
),
);
},
);
}
}

View File

@@ -0,0 +1,82 @@
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';
class TagsWidget extends StatefulWidget {
const TagsWidget({super.key});
@override
State<TagsWidget> createState() => _TagsWidgetState();
}
class _TagsWidgetState extends State<TagsWidget> {
final tagController = TextEditingController();
final List<String> tags = [];
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Теги'),
SizedBox(height: 4),
CustomTextFormField(
hintText: 'Например: без майонеза',
controller: tagController,
suffix: IconButton(
onPressed: () {
if (tagController.text.isNotEmpty) {
setState(() {
tags.add(tagController.text);
tagController.clear();
});
}
},
icon: Icon(
Icons.done,
color: appTheme.blueA400,
),
),
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (int i = 0; i < tags.length; i++) ...[
InkWell(
onTap: () {
setState(() {
tags.remove(tags[i]);
});
},
borderRadius: BorderRadius.circular(16),
child: Ink(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.grey.shade200,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
tags[i],
),
const SizedBox(width: 4),
Icon(
Icons.delete_outline_rounded,
color: Colors.grey.shade600,
size: 20,
),
],
),
),
),
],
],
),
],
);
}
}

View File

@@ -0,0 +1,213 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class TimeOfCookWidget extends StatefulWidget {
const TimeOfCookWidget({super.key});
@override
State<TimeOfCookWidget> createState() => _TimeOfCookWidgetState();
}
class _TimeOfCookWidgetState extends State<TimeOfCookWidget> {
late final CreateRecipeCubit createRecipeCubit;
@override
void initState() {
super.initState();
createRecipeCubit = context.read<CreateRecipeCubit>();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<CreateRecipeCubit, CreateRecipeState>(
buildWhen: (previous, current) =>
previous.activeTimeValidationError != current.activeTimeValidationError || previous.cookingTimeValidationError != current.cookingTimeValidationError,
builder: (context, state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Text('Общее время приготовления'),
const SizedBox(width: 8),
GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text(
'Общее время приготовления - это период времени от начала приготовления блюда до подачи его на стол.',
style: TextStyle(
fontWeight: FontWeight.w500,
color: Color(0xFF323F4B),
height: 1.2,
),
),
),
);
},
child: Icon(
Icons.help_outline_rounded,
color: appTheme.blueA400,
size: 20,
),
),
],
),
SizedBox(height: 4),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
children: [
CustomTextFormField(
hintText: 'Часов',
hasError: state.cookingTimeValidationError != null,
textInputType: TextInputType.number,
onChanged: (value) {
final hours = int.tryParse(value);
if (hours == null) return;
createRecipeCubit.setTotalCookingHours(hours);
if (state.cookingTimeValidationError != null) {
createRecipeCubit.validateTotalCookTime();
}
},
),
if (state.cookingTimeValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.cookingTimeValidationError!,
),
],
],
),
),
const SizedBox(width: 8),
Expanded(
child: Column(
children: [
CustomTextFormField(
hintText: 'Минут',
hasError: state.cookingTimeValidationError != null,
textInputType: TextInputType.number,
onChanged: (value) {
final minutes = int.tryParse(value);
if (minutes == null) return;
createRecipeCubit.setTotalCookingMinutes(minutes);
if (state.cookingTimeValidationError != null) {
createRecipeCubit.validateTotalCookTime();
}
},
),
if (state.cookingTimeValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.cookingTimeValidationError!,
),
],
],
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Text('Активное время приготовления'),
const SizedBox(width: 8),
GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text(
'Активное время приготовления - это период времени, требующий активного участия в приготовлении блюда. Оно включает мытье и очистку продуктов, нарезку, шинковку, взбивание, перемешивание, размешивание, перекладывание и т.п.',
style: TextStyle(
fontWeight: FontWeight.w500,
color: Color(0xFF323F4B),
height: 1.2,
),
),
),
);
},
child: Icon(
Icons.help_outline_rounded,
color: appTheme.blueA400,
size: 20,
),
),
],
),
SizedBox(height: 4),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
children: [
CustomTextFormField(
hintText: 'Часов',
hasError: state.activeTimeValidationError != null,
textInputType: TextInputType.number,
onChanged: (value) {
final hours = int.tryParse(value);
if (hours == null) return;
createRecipeCubit.setActiveCookingHours(hours);
if (state.activeTimeValidationError != null) {
createRecipeCubit.validateActiveCookTime();
}
},
),
if (state.activeTimeValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.activeTimeValidationError!,
),
],
],
),
),
const SizedBox(width: 8),
Expanded(
child: Column(
children: [
CustomTextFormField(
hintText: 'Минут',
hasError: state.activeTimeValidationError != null,
textInputType: TextInputType.number,
onChanged: (value) {
final minutes = int.tryParse(value);
if (minutes == null) return;
createRecipeCubit.setActiveCookingMinutes(minutes);
if (state.activeTimeValidationError != null) {
createRecipeCubit.validateActiveCookTime();
}
},
),
if (state.activeTimeValidationError != null) ...[
SizedBox(height: 4),
CustomErrorWidget(
error: state.activeTimeValidationError!,
),
],
],
),
),
],
),
],
);
},
);
}
}