Skip to content

Commit

Permalink
fix: fixes error handling for delete requests
Browse files Browse the repository at this point in the history
  • Loading branch information
am-casper committed Apr 10, 2024
1 parent a692060 commit 2dc9e43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
44 changes: 30 additions & 14 deletions lib/presentation/profile/bloc/profile_page_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,35 @@ class ProfilePageBloc extends Bloc<ProfilePageEvent, ProfilePageState> {
DeleteHostelChangeRequest event, Emitter<ProfilePageState> 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),
),
);
}
}
}
2 changes: 1 addition & 1 deletion lib/presentation/profile/bloc/profile_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProfilePageFetchedState extends ProfilePageState {
});

final User user;
final dynamic hostelChangeStatus;
final HostelChangeRequest hostelChangeStatus;

@override
List<Object> get props => [user, hostelChangeStatus];
Expand Down
8 changes: 6 additions & 2 deletions lib/presentation/profile/profile_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: () {
Expand All @@ -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(
Expand Down

0 comments on commit 2dc9e43

Please sign in to comment.