Skip to content

Commit 2dc9e43

Browse files
committed
fix: fixes error handling for delete requests
1 parent a692060 commit 2dc9e43

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

lib/presentation/profile/bloc/profile_page_bloc.dart

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,35 @@ class ProfilePageBloc extends Bloc<ProfilePageEvent, ProfilePageState> {
5050
DeleteHostelChangeRequest event, Emitter<ProfilePageState> emit) async {
5151
emit(const ProfilePageInitialState());
5252
User user = await repo.getCurrentUser();
53-
await repo.deleteChangeHostel();
54-
emit(
55-
ProfilePageFetchedState(
56-
user: user,
57-
hostelChangeStatus: const HostelChangeRequest(
58-
user: 0,
59-
id: 0,
60-
hostelCode: "",
61-
newRoomNo: "",
62-
timestamp: "",
63-
newHostel: 0,
64-
isApprovedByAdmin: null),
65-
),
66-
);
53+
try {
54+
await repo.deleteChangeHostel();
55+
emit(
56+
ProfilePageFetchedState(
57+
user: user,
58+
hostelChangeStatus: const HostelChangeRequest(
59+
user: 0,
60+
id: 0,
61+
hostelCode: "",
62+
newRoomNo: "",
63+
timestamp: "",
64+
newHostel: 0,
65+
isApprovedByAdmin: null),
66+
),
67+
);
68+
} catch (e) {
69+
emit(
70+
ProfilePageFetchedState(
71+
user: user,
72+
hostelChangeStatus: const HostelChangeRequest(
73+
user: 0,
74+
id: 0,
75+
hostelCode: "",
76+
newRoomNo: "",
77+
timestamp: "",
78+
newHostel: 0,
79+
isApprovedByAdmin: null),
80+
),
81+
);
82+
}
6783
}
6884
}

lib/presentation/profile/bloc/profile_page_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ProfilePageFetchedState extends ProfilePageState {
2121
});
2222

2323
final User user;
24-
final dynamic hostelChangeStatus;
24+
final HostelChangeRequest hostelChangeStatus;
2525

2626
@override
2727
List<Object> get props => [user, hostelChangeStatus];

lib/presentation/profile/profile_view.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ class ProfileScreen extends StatelessWidget {
9393
],
9494
),
9595
10.toVerticalSizedBox,
96-
if (state.hostelChangeStatus.isApprovedByAdmin == null)
96+
if (state
97+
.hostelChangeStatus.isApprovedByAdmin ==
98+
null)
9799
ProfileTextButton(
98100
title: 'Request for Hostel Change',
99101
onPressed: () {
@@ -102,7 +104,9 @@ class ProfileScreen extends StatelessWidget {
102104
horizontalPadding: 50,
103105
width: 248,
104106
),
105-
if (state.hostelChangeStatus.isApprovedByAdmin != null)
107+
if (state
108+
.hostelChangeStatus.isApprovedByAdmin !=
109+
null)
106110
TextButton(
107111
onPressed: () => {
108112
showDialog(

0 commit comments

Comments
 (0)