forked from eatvio/eatvio_app
refactor(all): refactor
This commit is contained in:
@@ -37,7 +37,7 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
}
|
||||
final String? recipeID = state.recipeModelObj?.recipeID;
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/show/$recipeID'),
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipes/show/$recipeID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
@@ -47,7 +47,8 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
if (data is Map<String, dynamic>) {
|
||||
if (state is RecipeEditLoadedState) {
|
||||
var currentState = state as RecipeEditLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
recipeModelObj: currentState.recipeModelObj,
|
||||
title: currentState.title,
|
||||
token: currentState.token,
|
||||
@@ -56,7 +57,9 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
video_url: currentState.video_url,
|
||||
steps: currentState.steps,
|
||||
stepDescriptions: currentState.stepDescriptions,
|
||||
tags: currentState.tags,),);
|
||||
tags: currentState.tags,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final Map<String, dynamic> defaultStep = {
|
||||
'description': '',
|
||||
@@ -75,17 +78,19 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
}
|
||||
}
|
||||
|
||||
emit(RecipeEditLoadedState(
|
||||
token: token,
|
||||
recipe: data,
|
||||
title: TextEditingController(text: data['title']),
|
||||
description: TextEditingController(text: data['description']),
|
||||
video_url: TextEditingController(text: data['video_url']),
|
||||
tagsController: TextEditingController(),
|
||||
tags: await _fetchTags(data['id']),
|
||||
stepDescriptions: stepDescriptions,
|
||||
steps: steps,
|
||||
),);
|
||||
emit(
|
||||
RecipeEditLoadedState(
|
||||
token: token,
|
||||
recipe: data,
|
||||
title: TextEditingController(text: data['title']),
|
||||
description: TextEditingController(text: data['description']),
|
||||
video_url: TextEditingController(text: data['video_url']),
|
||||
tagsController: TextEditingController(),
|
||||
tags: await _fetchTags(data['id']),
|
||||
stepDescriptions: stepDescriptions,
|
||||
steps: steps,
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
||||
@@ -195,7 +200,7 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
}
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getTags/$id'),
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipes/getTags/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
@@ -213,7 +218,8 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
}
|
||||
if (state is RecipeEditLoadedState) {
|
||||
var currentState = state as RecipeEditLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
recipeModelObj: currentState.recipeModelObj,
|
||||
recipe: currentState.recipe,
|
||||
title: currentState.title,
|
||||
@@ -222,7 +228,9 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
video_url: currentState.video_url,
|
||||
steps: currentState.steps,
|
||||
stepDescriptions: currentState.stepDescriptions,
|
||||
tags: currentState.tags,),);
|
||||
tags: currentState.tags,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user