forked from eatvio/eatvio_app
feat(diary): Add portion finished
This commit is contained in:
@@ -381,15 +381,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
AddPortionEvent event, Emitter<DiaryEditState> emit) async {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
int? id = currentState.currentMeal?.id;
|
||||
var updatedState = currentState.copyWith(
|
||||
currentMeal: currentState.diaryEditModelObj?.mealList[id ?? 0],
|
||||
portions: currentState.meals?[id ?? 0]['portions'],
|
||||
mealTimeController:
|
||||
toTime(currentState.meals?[id ?? 0]['time'] ?? "1$id:00"),
|
||||
selectedMood: currentState.meals?[id ?? 0]['mood'],
|
||||
selectedSatiety: currentState.meals?[id ?? 0]['satiety']);
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
|
||||
// Отправляем данные по HTTP маршруту и ждем ответ
|
||||
var response = await sendPortionData(
|
||||
@@ -399,8 +392,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
int.parse(currentState.productQuantityController!.text),
|
||||
currentState.currentMeal!.id,
|
||||
currentState.diaryId);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var updatedState = currentState.copyWith(
|
||||
portions: currentState.meals?[id ?? 0]['portions'],
|
||||
);
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
}
|
||||
}
|
||||
@@ -415,13 +410,13 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
int diaryID,
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! +
|
||||
'diary/$diaryID/meal/$mealID/portions/create';
|
||||
'/diary/$diaryID/meal/$mealID/portions/create';
|
||||
final Map<String, dynamic> credentials = {
|
||||
'product_name': name,
|
||||
'portion': portion,
|
||||
'quantity': quantity,
|
||||
};
|
||||
|
||||
print(credentials);
|
||||
var response = await http.post(Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -430,6 +425,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8);
|
||||
|
||||
print(response.body);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -455,6 +451,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
jsonDecode(response.body)['product_nutritional_value'];
|
||||
if (productNutritionalValues is List<dynamic>) {
|
||||
var updatedState = currentState.copyWith(
|
||||
productNameController: TextEditingController(text: event.input),
|
||||
autocompleteList: productNutritionalValues
|
||||
.map((product) => product['name'])
|
||||
.toList());
|
||||
|
||||
Reference in New Issue
Block a user