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

@@ -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',
};

View File

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

View File

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