forked from eatvio/eatvio_app
feat(recipe): Main menu buttons and API implementtion
This commit is contained in:
@@ -35,12 +35,12 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
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<RecipeCreateEvent, RecipeCreateState> {
|
||||
|
||||
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<RecipeCreateEvent, RecipeCreateState> {
|
||||
|
||||
FutureOr<http.Response> 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<RecipeCreateEvent, RecipeCreateState> {
|
||||
final Map<String, dynamic> credentials = {
|
||||
'title': title,
|
||||
'description': description,
|
||||
'youtube_url': youtube_url,
|
||||
'video_url': video_url,
|
||||
'status': 'active',
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Object?> get props => [recipeModelObj, title, description, youtube_url];
|
||||
List<Object?> 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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)),
|
||||
));
|
||||
},
|
||||
),
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user