feat(recipe): Main menu buttons and API implementtion

This commit is contained in:
2024-05-14 12:14:33 +03:00
parent a32117953d
commit a440d31ab6
8 changed files with 48 additions and 28 deletions

View File

@@ -47,13 +47,13 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
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<RecipeEditEvent, RecipeEditState> {
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<RecipeEditEvent, RecipeEditState> {
FutureOr<http.Response> sendRecipe(
Map<String, dynamic>? recipe,
String? title,
String? youtube_url,
String? video_url,
String? description,
) async {
int id = recipe?['id'];
@@ -105,7 +105,11 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
'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(

View File

@@ -27,29 +27,29 @@ class RecipeEditLoadedState extends RecipeEditState {
this.recipe,
this.title,
this.description,
this.youtube_url});
this.video_url});
RecipeEditModel? recipeModelObj;
Map<String, dynamic>? recipe;
TextEditingController? title;
TextEditingController? description;
TextEditingController? youtube_url;
TextEditingController? video_url;
@override
List<Object?> get props =>
[recipeModelObj, recipe, title, description, youtube_url];
[recipeModelObj, recipe, title, description, video_url];
RecipeEditLoadedState copyWith({
RecipeEditModel? recipeModelObj,
Map<String, dynamic>? 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,
);
}
}

View File

@@ -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),