new test cases

This commit is contained in:
Username1548
2025-01-29 14:47:27 +07:00
parent 370e8883a0
commit 4242265830
39 changed files with 898 additions and 461 deletions

View File

@@ -1,14 +1,18 @@
import 'dart:io';
import 'package:eatvio_app/features/recipes/entities/recipe_create_entity.dart';
import 'package:eatvio_app/features/recipes/models/ingredient.dart';
import 'package:eatvio_app/features/recipes/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:eatvio_app/features/recipes/reporitories/recipe_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CreateRecipeCubit extends Cubit<CreateRecipeState> {
CreateRecipeCubit()
final RecipeRepository recipeRepository;
CreateRecipeCubit({required this.recipeRepository})
: super(
CreateRecipeState(
RecipeCreateEntity(
typeOfRecipe: TypeOfRecipe.first_meals,
ingredients: [],
steps: [],
tags: [],
@@ -38,7 +42,7 @@ class CreateRecipeCubit extends Cubit<CreateRecipeState> {
);
}
addIngredient(IngredientEntity entity) {
addIngredient(Ingredient entity) {
emit(
CreateRecipeState(
state.entity.copyWith(
@@ -52,7 +56,7 @@ class CreateRecipeCubit extends Cubit<CreateRecipeState> {
}
removeIngredient(int index) {
List<IngredientEntity> ingredients = [...state.entity.ingredients];
List<Ingredient> ingredients = [...state.entity.ingredients];
ingredients.removeAt(index);
emit(
@@ -65,8 +69,8 @@ class CreateRecipeCubit extends Cubit<CreateRecipeState> {
}
replaceIngredientPosition(int oldIndex, int newIndex) {
List<IngredientEntity> ingredients = [...state.entity.ingredients];
final IngredientEntity item = ingredients.removeAt(oldIndex);
List<Ingredient> ingredients = [...state.entity.ingredients];
final item = ingredients.removeAt(oldIndex);
ingredients.insert(newIndex, item);
emit(
CreateRecipeState(
@@ -216,4 +220,12 @@ class CreateRecipeCubit extends Cubit<CreateRecipeState> {
),
);
}
Future<void> publishRecipe() async {
try {
await recipeRepository.publishRecipe(state.entity.toModel());
} catch (e) {
rethrow;
}
}
}

View File

@@ -10,6 +10,9 @@ 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();
}
@@ -39,28 +42,34 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
InfoAboutRecipeWidget(),
IngredientsWidget(),
StepsWidget(),
InkWell(
onTap: () {},
borderRadius: BorderRadius.circular(20),
child: Ink(
width: MediaQuery.of(context).size.width - 32,
decoration: BoxDecoration(
color: appTheme.blueA400,
Builder(
builder: (context) {
return InkWell(
onTap: () {
context.read<CreateRecipeCubit>().publishRecipe();
},
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,
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

@@ -18,14 +18,7 @@ class InfoAboutRecipeWidget extends StatefulWidget {
}
class _InfoAboutRecipeWidgetState extends State<InfoAboutRecipeWidget> {
final List<SelectionPopupModel> items = const [
SelectionPopupModel(title: 'Первые Блюда'),
SelectionPopupModel(title: 'Вторые Блюда'),
SelectionPopupModel(title: 'Салаты'),
SelectionPopupModel(title: 'Сладости'),
SelectionPopupModel(title: 'Напитки'),
SelectionPopupModel(title: 'Прочее'),
];
final List<SelectionPopupModel> items = TypeOfRecipe.values.map((e) => SelectionPopupModel(title: e.toString())).toList();
late SelectionPopupModel selectedType;
late final CreateRecipeCubit createRecipeCubit;
@@ -64,14 +57,7 @@ class _InfoAboutRecipeWidgetState extends State<InfoAboutRecipeWidget> {
selectedType = newSelectedType;
});
createRecipeCubit.changeType(
switch (selectedType.title) {
'Первые Блюда' => TypeOfRecipe.first_meals,
'Вторые Блюда' => TypeOfRecipe.second_meals,
'Салаты' => TypeOfRecipe.salads,
'Сладости' => TypeOfRecipe.sweets,
'Напитки' => TypeOfRecipe.drinks,
_ => TypeOfRecipe.other,
},
TypeOfRecipe.fromString(selectedType.title) ?? TypeOfRecipe.other,
);
},
),

View File

@@ -1,6 +1,6 @@
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/recipes/entities/recipe_create_entity.dart';
import 'package:eatvio_app/features/recipes/models/ingredient.dart';
import 'package:eatvio_app/features/recipes/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
import 'package:eatvio_app/features/recipes/presentation/bloc/create_recipe_cubit/create_recipe_state.dart';
import 'package:flutter/material.dart';
@@ -161,7 +161,7 @@ class _IngredientsWidgetState extends State<IngredientsWidget> {
onTap: () {
if (nameController.text.isNotEmpty && (pcsController.text.isNotEmpty || gramsController.text.isNotEmpty)) {
createRecipeCubit.addIngredient(
IngredientEntity(
Ingredient(
name: nameController.text,
unit: gramsController.text.isEmpty ? pcsController.text : gramsController.text,
portion: gramsController.text.isEmpty ? 'pcs' : 'gr',