From 2dc9e43d05273a03424c55dd2353fab2545d76c3 Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Wed, 10 Apr 2024 23:33:11 +0530 Subject: [PATCH] fix: fixes error handling for delete requests --- .../profile/bloc/profile_page_bloc.dart | 44 +++++++++++++------ .../profile/bloc/profile_page_state.dart | 2 +- lib/presentation/profile/profile_view.dart | 8 +++- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/presentation/profile/bloc/profile_page_bloc.dart b/lib/presentation/profile/bloc/profile_page_bloc.dart index 8f1a87ea..5b1ba1fe 100644 --- a/lib/presentation/profile/bloc/profile_page_bloc.dart +++ b/lib/presentation/profile/bloc/profile_page_bloc.dart @@ -50,19 +50,35 @@ class ProfilePageBloc extends Bloc { DeleteHostelChangeRequest event, Emitter emit) async { emit(const ProfilePageInitialState()); User user = await repo.getCurrentUser(); - await repo.deleteChangeHostel(); - emit( - ProfilePageFetchedState( - user: user, - hostelChangeStatus: const HostelChangeRequest( - user: 0, - id: 0, - hostelCode: "", - newRoomNo: "", - timestamp: "", - newHostel: 0, - isApprovedByAdmin: null), - ), - ); + try { + await repo.deleteChangeHostel(); + emit( + ProfilePageFetchedState( + user: user, + hostelChangeStatus: const HostelChangeRequest( + user: 0, + id: 0, + hostelCode: "", + newRoomNo: "", + timestamp: "", + newHostel: 0, + isApprovedByAdmin: null), + ), + ); + } catch (e) { + emit( + ProfilePageFetchedState( + user: user, + hostelChangeStatus: const HostelChangeRequest( + user: 0, + id: 0, + hostelCode: "", + newRoomNo: "", + timestamp: "", + newHostel: 0, + isApprovedByAdmin: null), + ), + ); + } } } diff --git a/lib/presentation/profile/bloc/profile_page_state.dart b/lib/presentation/profile/bloc/profile_page_state.dart index 6c20137a..471b461f 100644 --- a/lib/presentation/profile/bloc/profile_page_state.dart +++ b/lib/presentation/profile/bloc/profile_page_state.dart @@ -21,7 +21,7 @@ class ProfilePageFetchedState extends ProfilePageState { }); final User user; - final dynamic hostelChangeStatus; + final HostelChangeRequest hostelChangeStatus; @override List get props => [user, hostelChangeStatus]; diff --git a/lib/presentation/profile/profile_view.dart b/lib/presentation/profile/profile_view.dart index 59176ea3..a36563d5 100644 --- a/lib/presentation/profile/profile_view.dart +++ b/lib/presentation/profile/profile_view.dart @@ -93,7 +93,9 @@ class ProfileScreen extends StatelessWidget { ], ), 10.toVerticalSizedBox, - if (state.hostelChangeStatus.isApprovedByAdmin == null) + if (state + .hostelChangeStatus.isApprovedByAdmin == + null) ProfileTextButton( title: 'Request for Hostel Change', onPressed: () { @@ -102,7 +104,9 @@ class ProfileScreen extends StatelessWidget { horizontalPadding: 50, width: 248, ), - if (state.hostelChangeStatus.isApprovedByAdmin != null) + if (state + .hostelChangeStatus.isApprovedByAdmin != + null) TextButton( onPressed: () => { showDialog(