forked from eatvio/eatvio_app
feat(recipe): Models, service and repository for eecpe create. Recipe create now uses cubit
This commit is contained in:
170
lib/features/recipes/presentation/bloc/recipe_create_cubit.dart
Normal file
170
lib/features/recipes/presentation/bloc/recipe_create_cubit.dart
Normal file
@@ -0,0 +1,170 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/features/recipes/models/ingredient.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:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class RecipeCreateCubit extends Cubit<RecipeCreateState> {
|
||||
final RecipeRepository recipeRepository;
|
||||
|
||||
RecipeCreateCubit({required this.recipeRepository})
|
||||
: super(const RecipeCreateState.loading());
|
||||
|
||||
loadRecipeCreate() {
|
||||
emit(const RecipeCreateStateLoading());
|
||||
try {
|
||||
emit(RecipeCreateState.loaded(
|
||||
picker: ImagePicker(),
|
||||
titleController: TextEditingController(),
|
||||
productNameController: TextEditingController(),
|
||||
ingredientController: TextEditingController(),
|
||||
stepDescriptionController: TextEditingController(),
|
||||
youtubeLinkController: TextEditingController(),
|
||||
stepControllers: [TextEditingController()],
|
||||
stepImages: [null],
|
||||
ingredients: [],
|
||||
numberOfSteps: 1,
|
||||
ingredientAsItems: false,
|
||||
types: [
|
||||
SelectionPopupModel(title: 'Первые блюда'),
|
||||
SelectionPopupModel(title: 'Вторые блюда'),
|
||||
SelectionPopupModel(title: 'Cалаты'),
|
||||
SelectionPopupModel(title: 'Перекусы/закуски'),
|
||||
SelectionPopupModel(title: 'Сладости'),
|
||||
SelectionPopupModel(title: 'Напитки'),
|
||||
SelectionPopupModel(title: 'Прочее'),
|
||||
],
|
||||
cookingTimes: [
|
||||
SelectionPopupModel(title: '10 минут'),
|
||||
SelectionPopupModel(title: '20 минут'),
|
||||
SelectionPopupModel(title: '30 минут'),
|
||||
SelectionPopupModel(title: '1 час'),
|
||||
SelectionPopupModel(title: '2 часа'),
|
||||
SelectionPopupModel(title: '10 дней'),
|
||||
],
|
||||
statuses: [
|
||||
SelectionPopupModel(title: 'Активна'),
|
||||
SelectionPopupModel(title: 'Неактивна'),
|
||||
],
|
||||
));
|
||||
} catch (e) {
|
||||
emit(RecipeCreateState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
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<XFile?>.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.product_name == ingredient.product_name);
|
||||
|
||||
if (ingredientExists) {
|
||||
emit(RecipeCreateState.error(
|
||||
errorMessage: 'Ингредиент уже существует.'));
|
||||
return;
|
||||
}
|
||||
|
||||
List<Ingredient> newIngredients =
|
||||
List<Ingredient>.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<XFile?> newStepImages = List<XFile?>.from(currentState.stepImages);
|
||||
newStepImages.add(null);
|
||||
List<TextEditingController> newStepControllers =
|
||||
List<TextEditingController>.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<XFile?> newStepImages = currentState.stepImages;
|
||||
newStepImages.removeLast();
|
||||
List<TextEditingController> newStepControllers =
|
||||
List<TextEditingController>.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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:eatvio_app/features/recipes/models/recipe_model.dart';
|
||||
import 'package:eatvio_app/features/recipes/models/ingredient.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import '../../../../data/models/selectionPopupModel/selection_popup_model.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 youtubeLinkController,
|
||||
required List<TextEditingController> stepControllers,
|
||||
XFile? recipeImage,
|
||||
required List<XFile?> stepImages,
|
||||
required List<Ingredient> ingredients,
|
||||
required int numberOfSteps,
|
||||
required bool ingredientAsItems,
|
||||
required List<SelectionPopupModel> types,
|
||||
required List<SelectionPopupModel> cookingTimes,
|
||||
required List<SelectionPopupModel> statuses,
|
||||
}) = RecipeCreateStateLoaded;
|
||||
|
||||
const factory RecipeCreateState.error({
|
||||
required String errorMessage,
|
||||
}) = RecipeCreateStateError;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,72 +1,56 @@
|
||||
//import 'dart:io';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/core/app_export.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/image.dart' as image;
|
||||
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/widgets/custom_drop_down.dart';
|
||||
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class RecipeCreateScreen extends StatefulWidget {
|
||||
RecipeCreateScreen({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<RecipeCreateScreen> createState() => _RecipeCreateScreenState();
|
||||
}
|
||||
|
||||
class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
final TextEditingController titleController = TextEditingController();
|
||||
|
||||
final TextEditingController productNameController = TextEditingController();
|
||||
|
||||
final TextEditingController portionController = TextEditingController();
|
||||
|
||||
final TextEditingController stepDescriptionController =
|
||||
TextEditingController();
|
||||
|
||||
final TextEditingController youtubeLinkController = TextEditingController();
|
||||
|
||||
final List<SelectionPopupModel> types = [
|
||||
SelectionPopupModel(title: 'Первые блюда'),
|
||||
SelectionPopupModel(title: 'Вторые блюда'),
|
||||
SelectionPopupModel(title: 'Cалаты'),
|
||||
SelectionPopupModel(title: 'Перекусы/закуски'),
|
||||
SelectionPopupModel(title: 'Сладости'),
|
||||
SelectionPopupModel(title: 'Напитки'),
|
||||
SelectionPopupModel(title: 'Прочее'),
|
||||
];
|
||||
|
||||
final List<SelectionPopupModel> cookingTimes = [
|
||||
SelectionPopupModel(title: '10 минут'),
|
||||
SelectionPopupModel(title: '20 минут'),
|
||||
SelectionPopupModel(title: '30 минут'),
|
||||
SelectionPopupModel(title: '1 час'),
|
||||
SelectionPopupModel(title: '2 часа'),
|
||||
SelectionPopupModel(title: '10 дней'),
|
||||
];
|
||||
|
||||
final List<SelectionPopupModel> statuses = [
|
||||
SelectionPopupModel(title: 'Активна'),
|
||||
SelectionPopupModel(title: 'Неактивна'),
|
||||
];
|
||||
|
||||
int numberOfSteps = 1;
|
||||
XFile? recipeImage; // Переменная для общей фотографии рецепта
|
||||
List<XFile?> stepImages = []; // Список фотографий для каждого шага
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
bool portionAsItems = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
stepImages.add(null); // Добавляем начальный элемент для первого шага
|
||||
// ignore: must_be_immutable
|
||||
class RecipeCreateScreen extends StatelessWidget {
|
||||
RecipeCreateScreen({Key? key}) : super(key: key);
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<RecipeCreateCubit, RecipeCreateState>(
|
||||
builder: (context, state) {
|
||||
if (state is RecipeCreateStateLoaded) {
|
||||
return _buildRecipeCreate(context, state);
|
||||
} else if (state is RecipeCreateStateLoading) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: CupertinoActivityIndicator(),
|
||||
),
|
||||
);
|
||||
} 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 build(BuildContext context) {
|
||||
Widget _buildRecipeCreate(
|
||||
BuildContext context, RecipeCreateStateLoaded state) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 0,
|
||||
@@ -94,30 +78,28 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
Text('Заголовок'),
|
||||
SizedBox(height: 8),
|
||||
CustomTextFormField(
|
||||
validator: _validateTitle,
|
||||
fillColor: appTheme.gray50,
|
||||
controller: titleController,
|
||||
controller: state.titleController,
|
||||
hintText: 'Заголовок',
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Тип блюда'),
|
||||
SizedBox(height: 8),
|
||||
CustomDropDown(
|
||||
value: types[0],
|
||||
items: types,
|
||||
value: state.types[0],
|
||||
items: state.types,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Изображение'),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final pickedFile = await _picker.pickImage(
|
||||
source: ImageSource.gallery);
|
||||
setState(() {
|
||||
recipeImage =
|
||||
pickedFile; // Сохраняем общее изображение рецепта
|
||||
});
|
||||
final pickedFile = await state.picker
|
||||
.pickImage(source: ImageSource.gallery);
|
||||
context
|
||||
.read<RecipeCreateCubit>()
|
||||
.uploadRecipeImage(pickedFile);
|
||||
},
|
||||
child: recipeImage == null
|
||||
child: state.recipeImage == null
|
||||
? Container(
|
||||
height: 128,
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
@@ -139,49 +121,53 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
],
|
||||
),
|
||||
)
|
||||
: Image.file(File(recipeImage!.path),
|
||||
: Image.file(File(state.recipeImage!.path),
|
||||
height: 200, fit: BoxFit.cover),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Время приготовления'),
|
||||
SizedBox(height: 8),
|
||||
CustomDropDown(
|
||||
items: cookingTimes,
|
||||
value: cookingTimes[0],
|
||||
items: state.cookingTimes,
|
||||
value: state.cookingTimes[0],
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Статус'),
|
||||
SizedBox(height: 8),
|
||||
CustomDropDown(
|
||||
items: statuses,
|
||||
value: statuses[0],
|
||||
items: state.statuses,
|
||||
value: state.statuses[0],
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
if (!state.ingredients.isEmpty)
|
||||
for (int j = 0; j < state.ingredients.length; j++)
|
||||
_buildIngredient(state.ingredients[j]),
|
||||
SizedBox(height: 24),
|
||||
CustomTextFormField(
|
||||
hintText: 'Введите название продукта',
|
||||
controller: productNameController,
|
||||
controller: state.productNameController,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
CustomTextFormField(
|
||||
hintText: 'Порция',
|
||||
fillColor: appTheme.gray50,
|
||||
controller: portionController,
|
||||
controller: state.ingredientController,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly
|
||||
],
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Row(children: [
|
||||
Text('гр'),
|
||||
Switch(
|
||||
value: portionAsItems,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
portionAsItems = value;
|
||||
});
|
||||
},
|
||||
activeColor: appTheme.blueA400, // Цвет активной части
|
||||
inactiveThumbColor:
|
||||
Colors.grey, // Цвет ползунка, когда выключен
|
||||
inactiveTrackColor: Colors
|
||||
.grey.shade300, // Цвет трека, когда выключен
|
||||
value: state.ingredientAsItems,
|
||||
onChanged: (bool value) => context
|
||||
.read<RecipeCreateCubit>()
|
||||
.switchUnits(value),
|
||||
activeColor: appTheme.blueA400,
|
||||
inactiveThumbColor: Colors.grey,
|
||||
inactiveTrackColor: Colors.grey.shade300,
|
||||
),
|
||||
Text('шт'),
|
||||
]),
|
||||
@@ -190,19 +176,27 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
height: 48,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: FloatingActionButton.extended(
|
||||
highlightElevation: 0,
|
||||
elevation: 0,
|
||||
focusElevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
backgroundColor: appTheme.blueA400,
|
||||
onPressed: () {},
|
||||
label: Text(
|
||||
'+',
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
highlightElevation: 0,
|
||||
elevation: 0,
|
||||
focusElevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
backgroundColor: appTheme.blueA400,
|
||||
label: Text(
|
||||
'+',
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
onPressed: () => context
|
||||
.read<RecipeCreateCubit>()
|
||||
.addIngredient(new Ingredient(
|
||||
product_name:
|
||||
state.productNameController.text,
|
||||
portion: int.parse(
|
||||
state.ingredientController.text),
|
||||
unit: state.ingredientAsItems
|
||||
? 'pcs'
|
||||
: 'gr'))),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
Text('Описание рецепта'),
|
||||
@@ -210,10 +204,11 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
CustomTextFormField(
|
||||
maxLines: 8,
|
||||
minLines: 8,
|
||||
controller: stepDescriptionController,
|
||||
controller: state.stepDescriptionController,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
for (int i = 0; i < numberOfSteps; i++) _buildStep(i),
|
||||
for (int i = 0; i < state.numberOfSteps; i++)
|
||||
_buildStep(context, i, state),
|
||||
SizedBox(height: 24),
|
||||
Container(
|
||||
height: 48,
|
||||
@@ -226,12 +221,8 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
backgroundColor: appTheme.blueA400,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
stepImages.add(null);
|
||||
numberOfSteps++;
|
||||
});
|
||||
},
|
||||
onPressed: () =>
|
||||
context.read<RecipeCreateCubit>().addStep(),
|
||||
label: Text(
|
||||
'+',
|
||||
style: theme.textTheme.titleSmall,
|
||||
@@ -250,14 +241,8 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
backgroundColor: Colors.grey,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if (numberOfSteps > 1) {
|
||||
numberOfSteps--;
|
||||
stepImages.removeLast();
|
||||
}
|
||||
});
|
||||
},
|
||||
onPressed: () =>
|
||||
context.read<RecipeCreateCubit>().removeStep(),
|
||||
label: Text(
|
||||
'-',
|
||||
style: theme.textTheme.titleSmall,
|
||||
@@ -270,7 +255,7 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
CustomTextFormField(
|
||||
hintText: 'Введите описание шага',
|
||||
fillColor: appTheme.gray50,
|
||||
controller: youtubeLinkController,
|
||||
controller: state.youtubeLinkController,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
Container(
|
||||
@@ -300,25 +285,25 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
_buildStep(int stepNumber) {
|
||||
_buildStep(
|
||||
BuildContext context, int stepNumber, RecipeCreateStateLoaded state) {
|
||||
return Column(
|
||||
children: [
|
||||
Row(children: [
|
||||
Text('Шаг ${stepNumber + 1}'),
|
||||
Spacer(),
|
||||
Text('Всего шагов: $numberOfSteps')
|
||||
Text('Всего шагов: ${state.numberOfSteps}')
|
||||
]),
|
||||
SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final pickedFile =
|
||||
await _picker.pickImage(source: ImageSource.gallery);
|
||||
setState(() {
|
||||
stepImages[stepNumber] =
|
||||
pickedFile; // Сохраняем изображение для текущего шага
|
||||
});
|
||||
await state.picker.pickImage(source: ImageSource.gallery);
|
||||
context
|
||||
.read<RecipeCreateCubit>()
|
||||
.uploadStepImage(pickedFile, stepNumber);
|
||||
},
|
||||
child: stepImages[stepNumber] == null
|
||||
child: state.stepImages[stepNumber] == null
|
||||
? Container(
|
||||
height: 128,
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
@@ -341,7 +326,7 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
],
|
||||
),
|
||||
)
|
||||
: Image.file(File(stepImages[stepNumber]!.path),
|
||||
: Image.file(File(state.stepImages[stepNumber]!.path),
|
||||
height: 150, fit: BoxFit.cover)),
|
||||
SizedBox(height: 16),
|
||||
CustomTextFormField(
|
||||
@@ -349,28 +334,96 @@ class _RecipeCreateScreenState extends State<RecipeCreateScreen> {
|
||||
maxLines: 8,
|
||||
minLines: 8,
|
||||
fillColor: appTheme.gray50,
|
||||
controller: state.stepControllers[stepNumber],
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
addImage(BuildContext context, bool isLoading) {
|
||||
if (!isLoading) {
|
||||
return () async {
|
||||
final picker = ImagePicker();
|
||||
XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
||||
if (image != null) {
|
||||
context.read<BlogPostCreateBloc>().add(UploadImages(image));
|
||||
_buildIngredient(Ingredient ingredient) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8.h,
|
||||
vertical: 6.v,
|
||||
),
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 7.h,
|
||||
top: 5.v,
|
||||
),
|
||||
child: Text(
|
||||
ingredient.product_name.length > 8
|
||||
? ingredient.product_name.substring(0, 8)
|
||||
: ingredient.product_name,
|
||||
style: CustomTextStyles.titleMedium16,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20.h,
|
||||
top: 3.v,
|
||||
bottom: 3.v,
|
||||
),
|
||||
child: Text(
|
||||
ingredient.portion.toString() +
|
||||
' ' +
|
||||
ingredient.unit.toString().tr,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
GestureDetector(
|
||||
// onTap: removeIngredient(context, ingredient),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: appTheme.blueGray300,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
RecipeModel createRecipeFromState(RecipeCreateStateLoaded state) {
|
||||
// Подготовка ингредиентов
|
||||
List<Ingredient> ingredients = state.ingredients;
|
||||
|
||||
// Подготовка шагов (например, можно создать шаги из stepControllers)
|
||||
List<step.Step> 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));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String? _validateTitle(value) {
|
||||
if (value!.isEmpty) {
|
||||
return 'Пожалуйста, введите заголовок';
|
||||
// Подготовка изображения
|
||||
image.Image pic = image.Image(path: state.recipeImage?.path ?? '');
|
||||
|
||||
// Создание экземпляра RecipeModel
|
||||
return RecipeModel(
|
||||
id: null,
|
||||
ingredients: ingredients,
|
||||
steps: steps,
|
||||
state: 'draft',
|
||||
description: state.titleController.text,
|
||||
type: state.types.first.value,
|
||||
image: pic,
|
||||
video_url: state.youtubeLinkController.text.isNotEmpty
|
||||
? state.youtubeLinkController.text
|
||||
: null,
|
||||
cooking_time:
|
||||
state.cookingTimes.isNotEmpty ? state.cookingTimes.first.value : null,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user