ProfileBloc constructor
ProfileBloc()
Implementation
ProfileBloc() : super(const ProfileState()) {
on<SetLangIndex>((event, emit) {
emit(state.copyWith(langIndex: event.index));
});
on<CheckMyId>((event, emit) async {
emit(state.copyWith(isButtonLoading: true));
final res = await profileRepository.checkMyId(event.context, event.code);
res.fold((l) {
emit(state.copyWith(isButtonLoading: false, profile: l));
}, (r) {
emit(state.copyWith(isButtonLoading: false));
AppHelper.errorSnackBar(
context: event.context,
message: r,
);
});
});
on<GetProfile>((event, emit) async {
emit(state.copyWith(isLoading: true));
final res = await profileRepository.getProfile(event.context);
res.fold((profile) {
if ((profile.passedTest ?? false) &&
(profile.myId ?? false) &&
!(profile.isBlocked ?? false) &&
(profile.visitedOffice ?? false) &&
(profile.selfEmploymentStatusSet ?? false) &&
(profile.equipmentId != null)) {
LocalStorage.setOnline(profile.isWorking ?? false);
} else {
LocalStorage.setOnline(false);
// if (profile.isWorking ?? false) {
// WebSocketService.toggleWorking(event.context);
// }
}
emit(
state.copyWith(
isLoading: false,
profile: profile,
checkLocker: profile.lockerSyncValue == null ? false : true,
),
);
}, (r) {
emit(state.copyWith(isLoading: false));
AppHelper.errorSnackBar(
context: event.context,
message: r,
);
});
});
on<UploadLicense>((event, emit) async {
emit(state.copyWith(isButtonLoading: true));
final res = await uploadRepository.uploadDriverLicense(
front: state.frontImage,
back: state.backImage,
context: event.context);
res.fold((l) async {
emit(state.copyWith(
isButtonLoading: false, frontImage: null, backImage: null));
}, (r) {
emit(state.copyWith(isButtonLoading: false));
AppHelper.errorSnackBar(
context: event.context,
message: r,
);
});
});
on<SetImagesLicense>((event, emit) {
emit(state.copyWith(
frontImage: event.front ?? state.frontImage,
backImage: event.back ?? state.backImage));
});
on<SetOnlineAndOffline>((event, emit) {
emit(state.copyWith(isButtonLoading: true));
LocalStorage.setOnline(event.value);
emit(state.copyWith(isButtonLoading: false));
});
on<SetImagesProfile>((event, emit) {
emit(state.copyWith(profileImage: event.profile));
});
on<CheckLockerUi>((event, emit) {
emit(state.copyWith(checkLocker: event.show));
});
on<UpdateProfile>((event, emit) async {
emit(state.copyWith(isButtonLoading: true));
final res = await profileRepository.updateProfile(
context: event.context,
firstName: event.firstName,
image: state.profileImage,
lastName: event.lastName);
res.fold((result) {
ProfileModel? profile = state.profile?.copyWith(
firstName: result.firstName,
lastName: result.lastName,
profilePhoto: result.profilePhoto,
);
emit(state.copyWith(
isButtonLoading: false,
profile: profile,
profileImage: null,
));
Navigator.pop(event.context);
}, (r) {
emit(state.copyWith(isButtonLoading: false));
AppHelper.errorSnackBar(
context: event.context,
message: r,
);
});
});
// on<GetReview>((event, emit) async {
// if (event.isRefresh ?? false) {
// event.controller?.resetNoData();
//
// emit(state.copyWith(reviewList: [], isLoading: true));
// }
// final res = await orderRepository.getReviewList(
// context: event.context, skip: state.reviewList.length);
//
// res.fold((value) async {
// final List<ReviewModel> list = List.from(state.reviewList);
// list.addAll(value.data ?? []);
// emit(state.copyWith(isLoading: false, reviewList: list));
// if (event.isRefresh ?? false) {
// event.controller?.refreshCompleted();
// return;
// } else if (value.data?.isEmpty ?? true) {
// event.controller?.loadNoData();
// return;
// }
// event.controller?.loadComplete();
// }, (r) {
// emit(state.copyWith(isLoading: false));
// if (event.isRefresh ?? false) {
// event.controller?.refreshFailed();
// }
// event.controller?.loadFailed();
// AppHelper.errorSnackBar(
// context: event.context,
// message: r,
// );
// });
// });
}