From a440d31ab6f4efa863a530820d2f52ef7e2e2b93 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 14 May 2024 12:14:33 +0300 Subject: [PATCH] feat(recipe): Main menu buttons and API implementtion --- .../bloc/recipe_create_bloc.dart | 12 ++++++------ .../bloc/recipe_create_state.dart | 10 +++++----- .../recipe_create_screen.dart | 2 +- .../bloc/recipe_edit_bloc.dart | 16 ++++++++++------ .../bloc/recipe_edit_state.dart | 10 +++++----- .../recipe_edit_screen/recipe_edit_screen.dart | 2 +- .../recipe_select_screen.dart | 18 +++++++++++++++++- .../recipe_show_screen/recipe_show_screen.dart | 6 +++--- 8 files changed, 48 insertions(+), 28 deletions(-) diff --git a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart index fa38bae4..d438c245 100644 --- a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart +++ b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_bloc.dart @@ -35,12 +35,12 @@ class RecipeCreateBloc extends Bloc { recipeModelObj: currentState.recipeModelObj, title: currentState.title, description: currentState.description, - youtube_url: currentState.youtube_url)); + video_url: currentState.video_url)); } else { emit(RecipeCreateLoadedState( title: TextEditingController(), description: TextEditingController(), - youtube_url: TextEditingController())); + video_url: TextEditingController())); } } @@ -51,12 +51,12 @@ class RecipeCreateBloc extends Bloc { var response = await sendRecipe( currentState.title?.text, - currentState.youtube_url?.text, + currentState.video_url?.text, currentState.description?.text, ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.recipeScreen); + NavigatorService.pushNamed(AppRoutes.recipeSelectScreen); } else { print( 'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}'); @@ -66,7 +66,7 @@ class RecipeCreateBloc extends Bloc { FutureOr sendRecipe( String? title, - String? youtube_url, + String? video_url, String? description, ) async { String url = '${dotenv.env['SERVER_ROOT']!}/recipe/create'; @@ -74,7 +74,7 @@ class RecipeCreateBloc extends Bloc { final Map credentials = { 'title': title, 'description': description, - 'youtube_url': youtube_url, + 'video_url': video_url, 'status': 'active', }; diff --git a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart index 59e5ddf8..cf5b12e3 100644 --- a/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart +++ b/lib/presentation/recipe/recipe_create_screen/bloc/recipe_create_state.dart @@ -23,25 +23,25 @@ class RecipeCreateState extends Equatable { class RecipeCreateLoadedState extends RecipeCreateState { RecipeCreateLoadedState( - {this.recipeModelObj, this.title, this.description, this.youtube_url}); + {this.recipeModelObj, this.title, this.description, this.video_url}); RecipeCreateModel? recipeModelObj; TextEditingController? title; TextEditingController? description; - TextEditingController? youtube_url; + TextEditingController? video_url; @override - List get props => [recipeModelObj, title, description, youtube_url]; + List get props => [recipeModelObj, title, description, video_url]; RecipeCreateLoadedState copyWith({ RecipeCreateModel? recipeModelObj, TextEditingController? title, TextEditingController? description, - TextEditingController? youtube_url, + TextEditingController? video_url, }) { return RecipeCreateLoadedState( recipeModelObj: recipeModelObj ?? this.recipeModelObj, title: title ?? this.title, description: description ?? this.description, - youtube_url: youtube_url ?? this.youtube_url, + video_url: video_url ?? this.video_url, ); } } 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 1bfc592c..ad4c7edf 100644 --- a/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart +++ b/lib/presentation/recipe/recipe_create_screen/recipe_create_screen.dart @@ -81,7 +81,7 @@ class RecipeCreateScreen extends StatelessWidget { ), SizedBox(height: 16.0), TextFormField( - controller: state.youtube_url, + controller: state.video_url, decoration: InputDecoration(labelText: 'Ссылка'), ), SizedBox(height: 16.0), diff --git a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart index 3d1ccfa1..8cafde30 100644 --- a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart +++ b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_bloc.dart @@ -47,13 +47,13 @@ class RecipeEditBloc extends Bloc { recipe: currentState.recipe, title: currentState.title, description: currentState.description, - youtube_url: currentState.youtube_url)); + video_url: currentState.video_url)); } else { emit(RecipeEditLoadedState( recipe: data, title: TextEditingController(text: data['title']), description: TextEditingController(text: data['description']), - youtube_url: TextEditingController(text: data['youtube_url']))); + video_url: TextEditingController(text: data['video_url']))); } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку @@ -78,12 +78,12 @@ class RecipeEditBloc extends Bloc { var response = await sendRecipe( currentState.recipe, currentState.title?.text, - currentState.youtube_url?.text, + currentState.video_url?.text, currentState.description?.text, ); if (response.statusCode == 200) { - NavigatorService.pushNamed(AppRoutes.blogPostScreen, + NavigatorService.pushNamed(AppRoutes.recipeScreen, arguments: currentState.recipe?['id'].toString()); } else { print( @@ -95,7 +95,7 @@ class RecipeEditBloc extends Bloc { FutureOr sendRecipe( Map? recipe, String? title, - String? youtube_url, + String? video_url, String? description, ) async { int id = recipe?['id']; @@ -105,7 +105,11 @@ class RecipeEditBloc extends Bloc { 'id': id, 'title': title, 'description': description, - 'youtube_url': youtube_url, + 'video_url': video_url, + 'steps': + '[{"image": "steps/bT91V52zY2hIkjZezUxO4jW4njfhDfCe2PcMxciZ.jpg", "description": "Excepturi fuga sed quaerat impedit facere recusandae. Nihil exercitationem architecto accusantium ut. Qui consequuntur rerum quam asperiores repellendus molestias."}, {"image": "steps/7vaLlotrw65NXbqaD0dK4OTLVyxMgmB9wL3xBzg3.jpg", "description": "Sit hic sint ullam qui. Odit nihil possimus quo id itaque nisi non."}, {"image": "steps/et7cKUsnQkegcRAE72TS0mfAf2jLJXW93QDAGfjz.jpg", "description": "Ab dolores qui voluptatem sed quasi vero. Culpa minus optio in voluptatibus aut corrupti. Dolor expedita minus aut nesciunt quos quibusdam rerum."}, {"image": "steps/260401J6r71r9kuUt694VcsuMMQKTlQMrlIwfaKo.jpg", "description": "Eos dolores corrupti cupiditate aut. Nam nesciunt eveniet eos nam vitae ut. Quibusdam ab commodi ut natus. Nisi earum porro quidem et eligendi iste doloribus."}, {"image": "steps/Ol10BkOFeZ9EG4BAShgB1wnVwtCimoUMcSNDh2EB.jpg", "description": "Consectetur optio porro nobis voluptas quibusdam. Consequatur dolor dolorem laboriosam magnam iste atque."}, {"image": "steps/8PanRq2aWWdXG1xCYkRyJ0M3Z39y6jMPfnHCqlVi.jpg", "description": "A optio porro eligendi ullam. Sed numquam ullam quasi aperiam inventore corrupti enim. Alias id et consequatur perferendis. Ullam consequatur incidunt nesciunt ut et aut."}, {"image": "steps/19U2sYSGDkprS3L8SIFT3xz59OwQJ5xs0A8etZjr.jpg", "description": "In doloribus vel voluptas dolorum. Temporibus iusto est repellat quo sed. Perspiciatis enim sit beatae in dolor ut. Quis ad qui eligendi nisi. Est suscipit dolore ratione dolores suscipit molestiae."}, {"image": "steps/CRxJtjgQw84kG3teJVtl9GqwWUQ1WKpvOeBbwf9a.jpg", "description": "Aut quia maiores et aut. Quidem ab voluptates blanditiis. Est quam quia repellat exercitationem rerum et iste mollitia. Et sed dolores tempore nam et similique qui."}, {"image": "steps/NoG9rHtvHNLrYI2LujURT3DMQCmEe68UbpiXco2y.jpg", "description": "Nam et dolorum delectus. Labore fuga asperiores nam cumque sit. Eum hic officiis ea asperiores qui. Soluta totam enim quasi explicabo sed aut."}]', + 'ingredients': + '[{"name": "Cheeseburger", "unit": "pcs", "portion": 336}, {"name": "Little Cheeseburger", "unit": "gr", "portion": 623}, {"name": "Bacon Burger", "unit": "ml", "portion": 713}, {"name": "Little Bacon Burger", "unit": "pcs", "portion": 160}, {"name": "Hamburger", "unit": "tablespoon", "portion": 390}, {"name": "Bacon Cheese Dog", "unit": "teespons", "portion": 295}, {"name": "Hamburger", "unit": "pcs", "portion": 813}, {"name": "Cheeseburger", "unit": "gr", "portion": 951}]' }; var response = await http.post( diff --git a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart index b13bbe53..ec001270 100644 --- a/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart +++ b/lib/presentation/recipe/recipe_edit_screen/bloc/recipe_edit_state.dart @@ -27,29 +27,29 @@ class RecipeEditLoadedState extends RecipeEditState { this.recipe, this.title, this.description, - this.youtube_url}); + this.video_url}); RecipeEditModel? recipeModelObj; Map? recipe; TextEditingController? title; TextEditingController? description; - TextEditingController? youtube_url; + TextEditingController? video_url; @override List get props => - [recipeModelObj, recipe, title, description, youtube_url]; + [recipeModelObj, recipe, title, description, video_url]; RecipeEditLoadedState copyWith({ RecipeEditModel? recipeModelObj, Map? recipe, TextEditingController? title, TextEditingController? description, - TextEditingController? youtube_url, + TextEditingController? video_url, }) { return RecipeEditLoadedState( recipeModelObj: recipeModelObj ?? this.recipeModelObj, recipe: recipe ?? this.recipe, title: title ?? this.title, description: description ?? this.description, - youtube_url: youtube_url ?? this.youtube_url, + video_url: video_url ?? this.video_url, ); } } diff --git a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart index 259b75b5..31a723a9 100644 --- a/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart +++ b/lib/presentation/recipe/recipe_edit_screen/recipe_edit_screen.dart @@ -96,7 +96,7 @@ class RecipeEditScreen extends StatelessWidget { ), SizedBox(height: 16.0), TextFormField( - controller: state.youtube_url, + controller: state.video_url, decoration: InputDecoration(labelText: 'Ссылка'), ), SizedBox(height: 16.0), diff --git a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart index a16b4906..20f1d78e 100644 --- a/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart +++ b/lib/presentation/recipe/recipe_select_screen/recipe_select_screen.dart @@ -40,7 +40,6 @@ class RecipeSelectScreen extends StatelessWidget { _buildSetingsScreen(BuildContext context, RecipeSelectLoadedState state) { mediaQueryData = MediaQuery.of(context); - print(state.posts); return SafeArea( child: Scaffold( backgroundColor: Colors.grey[200], @@ -86,6 +85,16 @@ class RecipeSelectScreen extends StatelessWidget { margin: EdgeInsets.only( left: 80.h, top: 12.v, bottom: 9.v), ), + Spacer(), + Padding( + padding: const EdgeInsets.only(right: 20.0), + child: GestureDetector( + onTap: () => Navigator.pushNamed( + context, + AppRoutes.recipeCreateScreen, + ), + child: Icon(Icons.create_outlined)), + ) ], ), ), @@ -140,6 +149,13 @@ class RecipeSelectScreen extends StatelessWidget { AppRoutes.recipeScreen, arguments: post?['id'].toString(), ), + trailing: GestureDetector( + onTap: () => Navigator.pushNamed( + context, + AppRoutes.recipeEditScreen, + arguments: post?['id'].toString(), + ), + child: Icon(Icons.edit)), )); }, ), diff --git a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart index b09c5efa..3576b5a6 100644 --- a/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart +++ b/lib/presentation/recipe/recipe_show_screen/recipe_show_screen.dart @@ -102,9 +102,9 @@ class RecipeScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ElevatedButton( - onPressed: () { - // Действие для редактирования - }, + onPressed: () => Navigator.pushNamed( + context, AppRoutes.recipeEditScreen, + arguments: state.recipe?['id'].toString()), child: Text('Редактировать'), ), ElevatedButton(