diff --git a/lib/app_router.dart b/lib/app_router.dart index 96851119..cd296118 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -11,6 +11,7 @@ import 'package:eatvio_app/features/diary/presentation/pages/diary_screen.dart'; import 'package:eatvio_app/features/feed/models/recipes_model.dart'; import 'package:eatvio_app/features/feed/presentation/pages/feed_screen.dart'; import 'package:eatvio_app/features/recipes/presentation/pages/about_recipes_screen.dart'; +import 'package:eatvio_app/features/recipes/presentation/pages/recipe_create_screen.dart'; import 'package:eatvio_app/features/registration/presentation/pages/registration_screen.dart'; import 'package:eatvio_app/presentation/auth/auth_screen/auth_screen.dart'; import 'package:eatvio_app/presentation/diets/diet_create_screen/diet_create_screen.dart'; @@ -92,6 +93,11 @@ class AppRouter { recipes: state.extra as Recipes, ), ), + GoRoute( + path: '/recipe-create-screen', + name: 'recipeCreateScreen', + builder: (context, state) => RecipeCreateScreen(), + ), GoRoute( path: '/blog-post-create-screen', name: 'blogPostCreateScreen', diff --git a/lib/features/recipes/presentation/pages/recipe_create_screen.dart b/lib/features/recipes/presentation/pages/recipe_create_screen.dart new file mode 100644 index 00000000..cb35e80c --- /dev/null +++ b/lib/features/recipes/presentation/pages/recipe_create_screen.dart @@ -0,0 +1,233 @@ +//import 'dart:io'; + +import 'package:eatvio_app/core/app_export.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'; + +class RecipeCreateScreen extends StatelessWidget { + const RecipeCreateScreen({ + super.key, + }); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + automaticallyImplyLeading: false, + ), + backgroundColor: Color.fromARGB(255, 240, 242, 245), + resizeToAvoidBottomInset: true, + body: SizedBox( + width: double.maxFinite, + child: Column( + children: [ + Expanded( + child: SingleChildScrollView( + child: Padding( + padding: EdgeInsets.only(bottom: 5), + 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( + validator: _validateTitle, + fillColor: appTheme.gray50, + hintText: 'Заголовок', + ), + SizedBox(height: 16), + Text('Тип блюда'), + SizedBox(height: 8), + CustomDropDown( + validator: _validateDescription, + ), + SizedBox(height: 16), + Text('Изображение'), + 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: 16), + Text('Время приготовления'), + SizedBox(height: 8), + CustomDropDown( + validator: _validateYouTubeLink, + ), + SizedBox(height: 16), + Text('Статус'), + SizedBox(height: 8), + CustomDropDown( + validator: _validateYouTubeLink, + ), + SizedBox(height: 24), + CustomTextFormField( + hintText: 'Введите название продукта', + validator: _validateYouTubeLink, + ), + SizedBox(height: 24), + CustomTextFormField( + hintText: 'Порция', + fillColor: appTheme.gray50, + validator: _validateYouTubeLink, + ), + SizedBox(height: 8), + CustomDropDown( + validator: _validateYouTubeLink, + ), + SizedBox(height: 8), + Container( + 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, + ), + ), + ), + SizedBox(height: 24), + Text('Описание рецепта'), + SizedBox(height: 8), + CustomTextFormField( + maxLines: 8, + minLines: 8, + validator: _validateYouTubeLink, + ), + SizedBox(height: 80), + ], + )), + ], + ), + ), + ), + ), + ], + ), + ), + ); + } +} + +/*_buildAddPhoto(BuildContext context, BlogPostCreateLoadedState state) { + bool isLoading = state.isLoading; + return GestureDetector( + onTap: addImage(context, isLoading), + child: Stack( + children: [ + if (state.image == 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, + ), + ], + ), + ), + if (state.image != null) + ClipRRect( + borderRadius: BorderRadius.circular(16), + child: Image( + image: FileImage( + File(state.image!.path), + ), + ), + ) + ], + ), + ); +}*/ + +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().add(UploadImages(image)); + } + }; + } +} + +String? _validateTitle(value) { + if (value!.isEmpty) { + return 'Пожалуйста, введите заголовок'; + } + return null; +} + +String? _validateDescription(value) { + if (value!.isEmpty) { + return 'Пожалуйста, введите описание'; + } + return null; +} + +String? _validateYouTubeLink(value) { + if (value!.isEmpty) { + return 'Пожалуйста, введите ссылку'; + } else if (!_isValidUrl(value)) { + return 'Пожалуйста, введите корректную ссылку'; + } + return null; +} + +bool _isValidUrl(String url) { + final RegExp urlRegExp = + new RegExp(r"^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$"); + return urlRegExp.hasMatch(url); +} diff --git a/lib/presentation/recipe/recipe_create_screen/models/recipe_create_model.dart b/lib/presentation/recipe/recipe_create_screen/models/recipe_create_model.dart index 1883aa86..b25f295e 100644 --- a/lib/presentation/recipe/recipe_create_screen/models/recipe_create_model.dart +++ b/lib/presentation/recipe/recipe_create_screen/models/recipe_create_model.dart @@ -6,14 +6,12 @@ import 'package:equatable/equatable.dart'; /// and is typically used to hold data that is passed between different parts of the application. class RecipeCreateModel extends Equatable { - final String recipeID; + RecipeCreateModel(); - RecipeCreateModel({required String recipeID}) : recipeID = recipeID; - - RecipeCreateModel copyWith(String recipeID) { - return RecipeCreateModel(recipeID: recipeID); + RecipeCreateModel copyWith() { + return RecipeCreateModel(); } @override - List get props => [recipeID]; + List get props => []; } diff --git a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart index 0f8f3f53..887e66f5 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -14,10 +14,10 @@ class RecipeCreateScreen extends StatelessWidget { const RecipeCreateScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { - final recipeID = ModalRoute.of(context)!.settings.arguments; return BlocProvider( - create: (context) => - RecipeCreateBloc(RecipeCreateState(recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString())))..add(RecipeCreateInitialEvent()), + create: (context) => RecipeCreateBloc( + RecipeCreateState(recipeModelObj: RecipeCreateModel())) + ..add(RecipeCreateInitialEvent()), child: RecipeCreateScreen(), ); } @@ -143,7 +143,8 @@ class RecipeCreateScreen extends StatelessWidget { Align(alignment: Alignment.centerLeft, child: Text("Изображение")), _buildAddPhoto(context, state), SizedBox(height: 16.0), - Align(alignment: Alignment.centerLeft, child: Text("Название рецепта")), + Align( + alignment: Alignment.centerLeft, child: Text("Название рецепта")), CustomTextFormField( controller: state.title, hintText: "Введите название рецепта", @@ -296,7 +297,8 @@ class RecipeCreateScreen extends StatelessWidget { text: "Добавить шаг", buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), - if (isLastStep && !isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага + if (isLastStep && + !isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага Column( children: [ SizedBox(height: 16.0), @@ -305,7 +307,8 @@ class RecipeCreateScreen extends StatelessWidget { Flexible( flex: 5, child: CustomOutlinedButton( - onPressed: () => context.read().add(AddStep()), + onPressed: () => + context.read().add(AddStep()), text: "Добавить шаг", buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), @@ -315,7 +318,8 @@ class RecipeCreateScreen extends StatelessWidget { flex: 1, child: CustomOutlinedButton( text: "х", - onPressed: () => context.read().add(RemoveStep(i)), + onPressed: () => + context.read().add(RemoveStep(i)), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), ), @@ -325,7 +329,8 @@ class RecipeCreateScreen extends StatelessWidget { ), if (!isLastStep && !isFirstStep) CustomOutlinedButton( - onPressed: () => context.read().add(RemoveStep(i)), + onPressed: () => + context.read().add(RemoveStep(i)), text: "x", buttonStyle: CustomButtonStyles.outlinePrimaryTL15, ), @@ -371,7 +376,9 @@ class RecipeCreateScreen extends StatelessWidget { ), ), SizedBox(height: 8.0), - Align(alignment: Alignment.centerLeft, child: Text("Ссылка на видео (необязательно)")), + Align( + alignment: Alignment.centerLeft, + child: Text("Ссылка на видео (необязательно)")), CustomTextFormField( controller: state.video_url, hintText: "YouTube",