feat(diary): Refresh page after product remove

This commit is contained in:
2024-03-25 15:07:25 +03:00
parent e22a32b645
commit ffbae3b502

View File

@@ -480,21 +480,11 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
currentState.diaryId,
);
print(currentState.portions);
print(response.body);
if (response.statusCode == 200) {
dynamic newPortion = jsonDecode(response.body)['portion'];
final updatedPortions = List.from(currentState.portions ?? [])
..add(newPortion);
final updatedState = currentState.copyWith(portions: updatedPortions);
print(updatedState.portions);
emit(updatedState); // Emit the updated state
await reloadScreen(event, emit);
} else {
// Handling error when response status code is not 200
print(
'Failed to add portion. Status Code: ${response.statusCode} ${response.body}');
}
@@ -582,7 +572,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
);
if (response.statusCode == 204) {
reloadScreen(event, emit);
await reloadScreen(event, emit);
} else {
print(
'Failed to add portion. Status Code: ${response.statusCode} ${response.body}');
}
}
}