From 56355f4e3152744fcc0de3acbbb37d262e62c9d4 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 29 Feb 2024 22:29:22 +0300 Subject: [PATCH] feat(diary): Saving filtering value to the state --- .../diary_edit_screen/bloc/diary_edit_bloc.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart index cb54d630..1aef9ac7 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart @@ -432,6 +432,7 @@ class DiaryEditBloc extends Bloc { ProductInput event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; + print(currentState.productNameController!.text); String? token = currentState.token; final credentials = { 'name': event.input, @@ -445,16 +446,18 @@ class DiaryEditBloc extends Bloc { 'Authorization': 'Bearer $token', }, ); - print(response.body); final productNutritionalValues = - jsonDecode(response.body)['productNutritionalValue']; - if (productNutritionalValues is Map) { + jsonDecode(response.body)['product_nutritional_value']; + if (productNutritionalValues is List) { var updatedState = currentState.copyWith( - autocompleteList: productNutritionalValues.values - .map((value) => value['name']) + autocompleteList: productNutritionalValues + .map((product) => product['name']) .toList()); + print(updatedState.autocompleteList); emit(updatedState); + } else { + print("Ошибка в декодировании ответа из API"); } } }