6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit dda35e3b

AuthorMikkel Thygesen<mikkelet@gmail.com>
Date2026-03-17 20:25:42 +0100
Added more logging

Changed files

.../lib/check_out/bloc/check_out_cubit.dart        | 48 +++++++++---------
 .../lib/contact/cubit/contact_cubit.dart           | 15 +++---
 .../lib/find_booking/cubit/find_booking_cubit.dart | 15 +++---
 .../lib/force_update/force_update_cubit.dart       | 24 ++++-----
 .../cubit/hotel_information_cubit.dart             |  7 +--
 comwell_key_app/lib/key/bloc/key_bloc.dart         | 24 +++++----
 .../lib/my_booking/cubit/my_booking_cubit.dart     | 24 ++++-----
 .../lib/presentation/app/bloc/profile_cubit.dart   |  4 +-
 .../bloc/booking_details_cubit.dart                | 29 +++++------
 .../screens/check_in/bloc/check_in_cubit.dart      | 10 ++--
 .../house_keeping/cubit/housekeeping_cubit.dart    | 12 ++---
 .../notification_permission_cubit.dart             |  4 +-
 .../bloc/permission_overview_cubit.dart            |  1 +
 .../pregistration/cubit/preregistration_cubit.dart | 57 +++++++++++-----------
 .../cubit/push_notification_cubit.dart             | 26 +++++-----
 .../lib/share/cubit/share_booking_cubit.dart       | 17 +++----
 .../lib/up_sales/cubit/up_sales_cubit.dart         |  8 +--
 17 files changed, 170 insertions(+), 155 deletions(-)

Diff

diff --git a/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart b/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart
index 0af4db75..e9fdcaf7 100644
--- a/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart
+++ b/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart
@@ -1,5 +1,5 @@
import 'package:adyen_checkout/adyen_checkout.dart';
-import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/check_out/bloc/check_out_state.dart';
import 'package:comwell_key_app/check_out/check_out_repository.dart';
import 'package:comwell_key_app/check_out/pages/check_out_page.dart';
@@ -18,7 +18,7 @@ import 'package:go_router/go_router.dart';
import 'package:payment_plugin/presentation/app/bloc/payment_cubit.dart';
import 'package:url_launcher/url_launcher.dart';
-class CheckoutCubit extends Cubit<CheckoutState> {
+class CheckoutCubit extends BaseCubit<CheckoutState> {
final ProfileRepository profileRepository = locator<ProfileRepository>();
final PreregistrationRepository preregistrationRepository = locator<PreregistrationRepository>();
final BookingDetailsRepository bookingDetailsRepository = locator<BookingDetailsRepository>();
@@ -37,30 +37,31 @@ class CheckoutCubit extends Cubit<CheckoutState> {
void init() async {
try {
//TODO: Fetch club points eventually
- emit(state.loading());
+ safeEmit(state.loading());
final user = await profileRepository.fetchProfileSettings();
- emit(state.clubPointsFetched(user.points));
+ safeEmit(state.clubPointsFetched(user.points));
booking = await bookingDetailsRepository.getRemoteBookingDetails(
booking.confirmationNumber,
booking.hotelCode,
);
setItems(booking.addOnItems ?? []);
- emit(state.loaded());
- } catch (e) {
- emit(state.checkoutError());
+ safeEmit(state.loaded());
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.checkoutError());
}
}
void onApplyClubPointsClicked(bool value) {
if (value) {
- emit(state.clubPointsApplied());
+ safeEmit(state.clubPointsApplied());
} else {
- emit(state.clubPointsRemoved());
+ safeEmit(state.clubPointsRemoved());
}
}
void setItems(Iterable<BookingAddonItem> items) {
- emit(state.itemsUpdated(items));
+ safeEmit(state.itemsUpdated(items));
}
Future<void> processPayment() async {
@@ -84,15 +85,17 @@ class CheckoutCubit extends Cubit<CheckoutState> {
booking.hotelCode,
);
await Future<void>.delayed(const Duration(milliseconds: 4000));
- } catch (e) {
- emit(state.checkoutError());
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.checkoutError());
}
}
Future<void> processCheckoutWithoutPaying() async {
try {
checkOut();
- } catch (e) {
+ } catch (e, st) {
+ logError(e, st);
await Future<void>.delayed(const Duration(milliseconds: 1000));
}
}
@@ -103,7 +106,7 @@ class CheckoutCubit extends Cubit<CheckoutState> {
switch (currentPage) {
case CheckoutPage.confirmation:
if (booking.balance == 0 || booking.balance == null) {
- emit(state.paymentProcessingNotNeeded());
+ safeEmit(state.paymentProcessingNotNeeded());
return _navigateToProcessing(context);
}
return _navigateTo(CheckoutPage.payment);
@@ -115,7 +118,7 @@ class CheckoutCubit extends Cubit<CheckoutState> {
void _navigateToProcessing(BuildContext context) {
_isAnimating = false;
if (!state.isTermsAccepted && (booking.balance ?? 0.0) > 0.0) {
- emit(state.showAcceptTermsError());
+ safeEmit(state.showAcceptTermsError());
} else {
if (booking.balance == 0 || booking.balance == null) {
processCheckoutWithoutPaying();
@@ -134,7 +137,7 @@ class CheckoutCubit extends Cubit<CheckoutState> {
.previousPage(duration: const Duration(milliseconds: 500), curve: Curves.fastOutSlowIn)
.then((_) {
_isAnimating = false;
- emit(state.pageChanged(currentPage));
+ safeEmit(state.pageChanged(currentPage));
});
return true;
}
@@ -145,7 +148,7 @@ class CheckoutCubit extends Cubit<CheckoutState> {
duration: const Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
);
- emit(state.pageChanged(page));
+ safeEmit(state.pageChanged(page));
_isAnimating = false;
}
@@ -157,9 +160,9 @@ class CheckoutCubit extends Cubit<CheckoutState> {
void onAcceptTermsChanged(bool value) {
if (value) {
- emit(state.termsAccepted());
+ safeEmit(state.termsAccepted());
} else {
- emit(state.termsDenied());
+ safeEmit(state.termsDenied());
}
}
@@ -172,9 +175,10 @@ class CheckoutCubit extends Cubit<CheckoutState> {
await checkOutRepository.checkOut(booking.confirmationNumber);
- emit(state.checkoutSuccess());
- } catch (e) {
- emit(state.checkoutError());
+ safeEmit(state.checkoutSuccess());
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.checkoutError());
await Future<void>.delayed(const Duration(milliseconds: 1000));
}
}
diff --git a/comwell_key_app/lib/contact/cubit/contact_cubit.dart b/comwell_key_app/lib/contact/cubit/contact_cubit.dart
index 744aa374..d632f47c 100644
--- a/comwell_key_app/lib/contact/cubit/contact_cubit.dart
+++ b/comwell_key_app/lib/contact/cubit/contact_cubit.dart
@@ -1,4 +1,4 @@
-import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/contact/repository/contact_repository.dart';
import 'package:comwell_key_app/domain/models/user.dart';
import 'package:comwell_key_app/overview/repository/overview_repository.dart';
@@ -10,7 +10,7 @@ import 'package:flutter/material.dart';
part 'contact_state.dart';
-class ContactCubit extends Cubit<ContactState> {
+class ContactCubit extends BaseCubit<ContactState> {
final ContactRepository _contactRepository;
final OverviewRepository _overviewRepository;
final ProfileRepository _profileRepository;
@@ -25,14 +25,15 @@ class ContactCubit extends Cubit<ContactState> {
) : super(const ContactState.initial());
Future<void> sendContact(String hotelCode) async {
- emit(const ContactState.contactSend());
+ safeEmit(const ContactState.contactSend());
try {
//final bookings = await _overviewRepository.fetchAllBookingsForUser();
// Send contact
//_contactRepository.sendContact(bookings.current.first.hotelCode);
- emit(const ContactState.contactSent());
- } catch (e) {
- emit(const ContactState.contactError());
+ safeEmit(const ContactState.contactSent());
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(const ContactState.contactError());
}
}
@@ -45,6 +46,6 @@ class ContactCubit extends Cubit<ContactState> {
phoneNumberController.text = phoneNumber;
- emit(state.userLoaded(user: user));
+ safeEmit(state.userLoaded(user: user));
}
}
diff --git a/comwell_key_app/lib/find_booking/cubit/find_booking_cubit.dart b/comwell_key_app/lib/find_booking/cubit/find_booking_cubit.dart
index aafe967f..3915b741 100644
--- a/comwell_key_app/lib/find_booking/cubit/find_booking_cubit.dart
+++ b/comwell_key_app/lib/find_booking/cubit/find_booking_cubit.dart
@@ -1,11 +1,11 @@
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/find_booking/cubit/find_booking_state.dart';
import 'package:comwell_key_app/find_booking/find_booking_repository.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/utils/locator.dart';
import 'package:flutter/material.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-class FindBookingCubit extends Cubit<FindBookingState> {
+class FindBookingCubit extends BaseCubit<FindBookingState> {
final FindBookingRepository findBookingRepository =
locator<FindBookingRepository>();
final TextEditingController confirmationIdController =
@@ -14,22 +14,23 @@ class FindBookingCubit extends Cubit<FindBookingState> {
FindBookingCubit() : super(FindBookingState()) {
confirmationIdController.addListener(() {
- emit(state.copyWith(isButtonEnabled: canContinue));
+ safeEmit(state.copyWith(isButtonEnabled: canContinue));
});
lastNameController.addListener(() {
- emit(state.copyWith(isButtonEnabled: canContinue));
+ safeEmit(state.copyWith(isButtonEnabled: canContinue));
});
}
Future<Booking?> findBooking(String confirmationId, String lastName) async {
try {
- emit(FindBookingState(isLoading: true));
+ safeEmit(FindBookingState(isLoading: true));
final booking = await findBookingRepository.findBookingByConfirmationId(
confirmationId, lastName);
return booking;
- } catch (e) {
- emit(FindBookingState(error: e.toString()));
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(FindBookingState(error: e.toString()));
return null;
}
}
diff --git a/comwell_key_app/lib/force_update/force_update_cubit.dart b/comwell_key_app/lib/force_update/force_update_cubit.dart
index e79daf14..bfdd8cfb 100644
--- a/comwell_key_app/lib/force_update/force_update_cubit.dart
+++ b/comwell_key_app/lib/force_update/force_update_cubit.dart
@@ -1,39 +1,39 @@
-import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/common/const.dart';
import 'package:in_app_update/in_app_update.dart';
import 'package:url_launcher/url_launcher.dart';
-import 'package:flutter/foundation.dart';
part 'force_update_state.dart';
-class ForceUpdateCubit extends Cubit<ForceUpdateState> {
+class ForceUpdateCubit extends BaseCubit<ForceUpdateState> {
ForceUpdateCubit() : super(ForceUpdateState.initial());
Future<void> startAndroidUpdate() async {
- emit(state.copyWith(isLoading: true, error: null));
+ safeEmit(state.copyWith(isLoading: true, error: null));
try {
final result = await InAppUpdate.checkForUpdate();
if (result.updateAvailability == UpdateAvailability.updateAvailable) {
await InAppUpdate.performImmediateUpdate();
} else {
- emit(state.copyWith(error: 'No update available.'));
+ safeEmit(state.copyWith(error: 'No update available.'));
}
- } catch (e) {
- emit(state.copyWith(error: 'Failed to update: $e'));
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.copyWith(error: 'Failed to update: $e'));
} finally {
- emit(state.copyWith(isLoading: false));
+ safeEmit(state.copyWith(isLoading: false));
}
}
Future<void> openAppStore() async {
- emit(state.copyWith(isLoading: true, error: null));
+ safeEmit(state.copyWith(isLoading: true, error: null));
//TODO: Add app store url to CONSTS
if (await canLaunchUrl(Uri.parse(AppStoreConstants.appStoreUrl))) {
await launchUrl(Uri.parse(AppStoreConstants.appStoreUrl), mode: LaunchMode.externalApplication);
} else {
- emit(state.copyWith(error: 'Could not open App Store.'));
+ safeEmit(state.copyWith(error: 'Could not open App Store.'));
}
- emit(state.copyWith(isLoading: false));
+ safeEmit(state.copyWith(isLoading: false));
}
-}
\ No newline at end of file
+}
diff --git a/comwell_key_app/lib/hotel_information/cubit/hotel_information_cubit.dart b/comwell_key_app/lib/hotel_information/cubit/hotel_information_cubit.dart
index aba9637f..5ddb2d46 100644
--- a/comwell_key_app/lib/hotel_information/cubit/hotel_information_cubit.dart
+++ b/comwell_key_app/lib/hotel_information/cubit/hotel_information_cubit.dart
@@ -4,7 +4,6 @@ import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/presentation/base/base_cubit.dart';
import 'package:comwell_key_app/services/api.dart';
import 'package:equatable/equatable.dart';
-import 'package:flutter/foundation.dart';
part 'hotel_information_state.dart';
@@ -44,10 +43,8 @@ class HotelInformationCubit extends BaseCubit<HotelInformationState> {
try {
await api.bookSpa(hotel);
} catch (e, st) {
- if (kDebugMode) {
- logError(e, st);
- }
+ logError(e, st);
}
- emit(state.bookingSpa(false));
+ safeEmit(state.bookingSpa(false));
}
}
diff --git a/comwell_key_app/lib/key/bloc/key_bloc.dart b/comwell_key_app/lib/key/bloc/key_bloc.dart
index e7aafffd..ce5ad621 100644
--- a/comwell_key_app/lib/key/bloc/key_bloc.dart
+++ b/comwell_key_app/lib/key/bloc/key_bloc.dart
@@ -4,6 +4,8 @@ import 'package:comwell_key_app/domain/repositories/booking_details_repository.d
import 'package:comwell_key_app/key/repository/key_repository.dart';
import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:equatable/equatable.dart';
+import 'package:flutter/foundation.dart';
+import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
part 'key_event.dart';
@@ -15,18 +17,19 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
final BookingDetailsRepository bookingDetailsRepository;
final SeosRepository seosRepository;
- KeyBloc(
- {required this.seosRepository,
- required this.keyRepository,
- required this.bookingDetailsRepository})
- : super(KeyState.unknown()) {
+ KeyBloc({
+ required this.seosRepository,
+ required this.keyRepository,
+ required this.bookingDetailsRepository,
+ }) : super(KeyState.unknown()) {
on<SearchForKeys>((event, emit) async {
emit(KeyState.searchForKeys());
try {
final keys = await seosRepository.refreshKeys();
emit(KeyState.validKeys(keys));
add(const StartScanning());
- } catch (e) {
+ } catch (e, st) {
+ if (!kDebugMode) Sentry.captureException(e, stackTrace: st);
emit(KeyState.searchForKeysError(e.toString()));
}
});
@@ -51,7 +54,8 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
// emit(KeyState.openClosestReaderError(e.toString()));
// }
// }
- } catch (e) {
+ } catch (e, st) {
+ if (!kDebugMode) Sentry.captureException(e, stackTrace: st);
emit(KeyState.scanningError(e.toString()));
}
});
@@ -59,7 +63,8 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
on<SetRootOpeningTrigger>((event, emit) async {
try {
await keyRepository.setRootOpeningTrigger();
- } catch (e) {
+ } catch (e, st) {
+ if (!kDebugMode) Sentry.captureException(e, stackTrace: st);
emit(KeyState.setRootOpeningTriggerError(e.toString()));
}
});
@@ -67,7 +72,8 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
on<RemoveRootOpeningTrigger>((event, emit) async {
try {
await keyRepository.removeRootOpeningTrigger();
- } catch (e) {
+ } catch (e, st) {
+ if (!kDebugMode) Sentry.captureException(e, stackTrace: st);
emit(KeyState.removeRootOpeningTriggerError(e.toString()));
}
});
diff --git a/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart b/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart
index b87169d3..e3bbdd96 100644
--- a/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart
+++ b/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart
@@ -1,3 +1,4 @@
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/my_booking/cubit/my_booking_state.dart';
import 'package:comwell_key_app/my_booking/my_booking_repository.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
@@ -5,13 +6,12 @@ import 'package:comwell_key_app/domain/repositories/profile_repository.dart';
import 'package:comwell_key_app/tracking/comwell_tracking.dart';
import 'package:comwell_key_app/tracking/models/analytics_event_item.dart';
import 'package:comwell_key_app/utils/locator.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:payment_plugin/presentation/app/bloc/payment_cubit.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../utils/urls.dart';
-class MyBookingCubit extends Cubit<MyBookingState> {
+class MyBookingCubit extends BaseCubit<MyBookingState> {
final MyBookingRepository myBookingRepository;
final ProfileRepository profileRepository = locator<ProfileRepository>();
late Booking booking;
@@ -41,9 +41,10 @@ class MyBookingCubit extends Cubit<MyBookingState> {
void init() async {
try {
// final user = await profileRepository.fetchProfileSettings();
- // emit(state.clubPointsFetched(user.points));
- } catch (e) {
- // emit(state.copyWith(error: e));
+ // safeEmit(state.clubPointsFetched(user.points));
+ } catch (e, st) {
+ logError(e, st);
+ // safeEmit(state.copyWith(error: e));
}
}
@@ -54,17 +55,17 @@ class MyBookingCubit extends Cubit<MyBookingState> {
void onAcceptTermsChanged(bool value) {
if (value) {
- emit(state.termsAccepted());
+ safeEmit(state.termsAccepted());
} else {
- emit(state.termsDenied());
+ safeEmit(state.termsDenied());
}
}
void onApplyClubPointsClicked(bool value) {
if (value) {
- emit(state.clubPointsApplied());
+ safeEmit(state.clubPointsApplied());
} else {
- emit(state.clubPointsRemoved());
+ safeEmit(state.clubPointsRemoved());
}
}
@@ -95,8 +96,9 @@ class MyBookingCubit extends Cubit<MyBookingState> {
booking.hotelCode,
);
await Future<void>.delayed(const Duration(milliseconds: 4000));
- } catch (e) {
- emit(state.setError());
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.setError());
}
}
}
diff --git a/comwell_key_app/lib/presentation/app/bloc/profile_cubit.dart b/comwell_key_app/lib/presentation/app/bloc/profile_cubit.dart
index 7533852f..38a0abfb 100644
--- a/comwell_key_app/lib/presentation/app/bloc/profile_cubit.dart
+++ b/comwell_key_app/lib/presentation/app/bloc/profile_cubit.dart
@@ -53,11 +53,11 @@ class ProfileCubit extends BaseCubit<ProfileState> {
}
void onToSClick(bool? value) async {
- emit(state.copyWith(isToSAccepted: value!));
+ safeEmit(state.copyWith(isToSAccepted: value!));
}
void onNewsletterClick(bool? value) async {
- emit(state.copyWith(isNewsletterAccepted: value!));
+ safeEmit(state.copyWith(isNewsletterAccepted: value!));
}
String getGender(String gender) {
diff --git a/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart b/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart
index f6566826..55544a33 100644
--- a/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart
@@ -12,7 +12,6 @@ import 'package:comwell_key_app/domain/repositories/profile_repository.dart';
import 'package:comwell_key_app/share/share_booking_repository.dart';
import 'package:comwell_key_app/up_sales/up_sales_repository.dart';
import 'package:comwell_key_app/utils/seos_repository.dart';
-import 'package:flutter/foundation.dart';
class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
late Booking booking;
@@ -56,8 +55,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
await getUpSales(fetchRemote: true);
}
await updateRemainingTime();
- } catch (e) {
- if (kDebugMode) print("err=$e");
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
} finally {
safeEmit(state.copyWith(isLoading: false));
@@ -79,8 +78,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
);
safeEmit(state.copyWith(upSales: response));
}
- } catch (e) {
- if (kDebugMode) print("err=$e");
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
@@ -109,8 +108,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
return booking;
}
- } catch (e) {
- if (kDebugMode) print("err=$e");
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
rethrow;
}
@@ -130,7 +129,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
final keys = await _seosRepository.refreshKeys();
safeEmit(state.copyWith(keys: keys));
}
- } catch (e) {
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
} finally {
safeEmit(state.copyWith(isLoadingKeys: false));
@@ -148,7 +148,7 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
);
if (isHouseKeepingOrdered) {
- emit(state.copyWith(isHouseKeepingOrdered: true));
+ safeEmit(state.copyWith(isHouseKeepingOrdered: true));
}
}
@@ -162,8 +162,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
);
await getUpSales(fetchRemote: true);
safeEmit(state.copyWith(isLoading: false));
- } catch (e) {
- if (kDebugMode) print("err=$e");
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
@@ -179,8 +179,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
await checkMobileKeys();
await getUpSales(fetchRemote: true);
safeEmit(state.copyWith(isLoading: false));
- } catch (e) {
- if (kDebugMode) print("err=$e");
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
@@ -204,7 +204,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
//TODO: add this when we have the backend
// await bookingDetailsRepository.updateBooking(event.booking);
safeEmit(state.copyWith(guests: booking.guests));
- } catch (e) {
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
diff --git a/comwell_key_app/lib/presentation/screens/check_in/bloc/check_in_cubit.dart b/comwell_key_app/lib/presentation/screens/check_in/bloc/check_in_cubit.dart
index 55ce1416..30dd8131 100644
--- a/comwell_key_app/lib/presentation/screens/check_in/bloc/check_in_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/check_in/bloc/check_in_cubit.dart
@@ -53,8 +53,8 @@ class CheckInCubit extends BaseCubit<CheckInState> {
setItems(booking.addOnItems ?? []);
safeEmit(state.copyWith(isLoading: false));
- } catch (e) {
- logError(e, StackTrace.current);
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(isLoading: false));
}
}
@@ -119,7 +119,8 @@ class CheckInCubit extends BaseCubit<CheckInState> {
booking.hotelCode,
);
await Future<void>.delayed(const Duration(milliseconds: 4000));
- } catch (e) {
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(paymentStatus: CheckInPaymentStatus.error));
}
}
@@ -192,11 +193,12 @@ class CheckInCubit extends BaseCubit<CheckInState> {
Future<void> _tryGetKeys({int attempt = 0}) async {
try {
await _checkInRepository.getKeys(booking.id, booking.hotelCode);
- } catch (e) {
+ } catch (e, st) {
if (attempt < _getKeysRetryAttempts) {
await Future<void>.delayed(const Duration(milliseconds: 500));
await _tryGetKeys(attempt: attempt + 1);
} else {
+ logError(e, st);
rethrow;
}
}
diff --git a/comwell_key_app/lib/presentation/screens/house_keeping/cubit/housekeeping_cubit.dart b/comwell_key_app/lib/presentation/screens/house_keeping/cubit/housekeeping_cubit.dart
index f81f8f88..f23cef66 100644
--- a/comwell_key_app/lib/presentation/screens/house_keeping/cubit/housekeeping_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/house_keeping/cubit/housekeeping_cubit.dart
@@ -1,5 +1,5 @@
-import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/domain/repositories/housekeeping_repository.dart';
+import 'package:comwell_key_app/presentation/base/base_cubit.dart';
import 'package:comwell_key_app/presentation/screens/house_keeping/cubit/housekeeping_state.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/tracking/comwell_tracking.dart';
@@ -8,7 +8,7 @@ import 'package:comwell_key_app/utils/locator.dart';
import '../components/housekeeping_service.dart';
-class HouseKeepingCubit extends Cubit<HouseKeepingState> {
+class HouseKeepingCubit extends BaseCubit<HouseKeepingState> {
final houseKeepingRepository = HouseKeepingRepository();
final tracking = locator<ComwellTracking>();
HouseKeepingCubit() : super(HouseKeepingState.initial());
@@ -23,13 +23,13 @@ class HouseKeepingCubit extends Cubit<HouseKeepingState> {
void onAddServiceClicked(String service) {
final List<String> updatedServices = List.from(state.selectedServices)
..add(service);
- emit(state.servicesSelected(selectedServices: updatedServices));
+ safeEmit(state.servicesSelected(selectedServices: updatedServices));
}
void onRemoveServiceClicked(String service) {
final List<String> updatedServices = List.from(state.selectedServices)
..remove(service);
- emit(state.servicesSelected(selectedServices: updatedServices));
+ safeEmit(state.servicesSelected(selectedServices: updatedServices));
}
void onServiceClicked(String name) {
@@ -41,7 +41,7 @@ class HouseKeepingCubit extends Cubit<HouseKeepingState> {
}
Future<List<String>> onOrderHousekeepingClicked(Booking booking) async {
-
+
final analyticsEventItem = AnalyticsEventItem(
hotelName: booking.hotelName,
currency: "DKK",
@@ -53,4 +53,4 @@ class HouseKeepingCubit extends Cubit<HouseKeepingState> {
tracking.trackAddToCart(analyticsEventItem);
return state.selectedServices.toList();
}
-}
\ No newline at end of file
+}
diff --git a/comwell_key_app/lib/presentation/screens/onboarding/notifications/notification_permission_cubit.dart b/comwell_key_app/lib/presentation/screens/onboarding/notifications/notification_permission_cubit.dart
index bbe4d5ba..7429df9c 100644
--- a/comwell_key_app/lib/presentation/screens/onboarding/notifications/notification_permission_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/onboarding/notifications/notification_permission_cubit.dart
@@ -1,5 +1,5 @@
import 'package:app_settings/app_settings.dart';
-import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/presentation/base/base_cubit.dart';
import 'package:comwell_key_app/domain/models/app_error.dart';
import 'package:comwell_key_app/utils/secure_storage.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -7,7 +7,7 @@ import 'package:permission_handler/permission_handler.dart';
part '../../../../.generated/presentation/screens/onboarding/notifications/notification_permission_cubit.freezed.dart';
-class NotificationPermissionCubit extends Cubit<NotificationPermissionState> {
+class NotificationPermissionCubit extends BaseCubit<NotificationPermissionState> {
NotificationPermissionCubit(
this._preferences,
) : super(const NotificationPermissionState()) {
diff --git a/comwell_key_app/lib/presentation/screens/permission_overview/bloc/permission_overview_cubit.dart b/comwell_key_app/lib/presentation/screens/permission_overview/bloc/permission_overview_cubit.dart
index 8db5f360..fd89314b 100644
--- a/comwell_key_app/lib/presentation/screens/permission_overview/bloc/permission_overview_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/permission_overview/bloc/permission_overview_cubit.dart
@@ -32,6 +32,7 @@ class PermissionOverviewCubit extends BaseCubit<PermissionOverviewState> {
_checkPushNotificationPermission(),
]);
} catch (e, st) {
+ logError(e, st);
safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
} finally {
safeEmit(state.copyWith(isLoading: false));
diff --git a/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart b/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
index 38c27006..286c2b32 100644
--- a/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
@@ -99,47 +99,47 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
);
} catch (e, st) {
logError(e, st);
- emit(state.copyWith(isLoading: false));
+ safeEmit(state.copyWith(isLoading: false));
}
}
void setupListeners() {
phoneNumberTextController.addListener(() {
if (state.missingInformation) {
- emit(state.copyWith(missingInformation: false));
+ safeEmit(state.copyWith(missingInformation: false));
} else {
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
}
});
addressTextController.addListener(() {
if (state.missingInformation) {
- emit(state.copyWith(missingInformation: false));
+ safeEmit(state.copyWith(missingInformation: false));
} else {
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
}
});
postalCodeTextController.addListener(() {
if (state.missingInformation) {
- emit(state.copyWith(missingInformation: false));
+ safeEmit(state.copyWith(missingInformation: false));
} else {
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
}
});
cityTextController.addListener(() {
if (state.missingInformation) {
- emit(state.copyWith(missingInformation: false));
+ safeEmit(state.copyWith(missingInformation: false));
} else {
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
}
});
}
void onDocumentTypeSelected(IdType documentType) {
selectedDocumentType = documentType;
- emit(state.copyWith(selectedDocumentType: documentType));
+ safeEmit(state.copyWith(selectedDocumentType: documentType));
}
void onAddressContinueClicked() {
@@ -153,10 +153,10 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
),
);
- emit(state.copyWith(user: updatedUser));
+ safeEmit(state.copyWith(user: updatedUser));
_navigateNextPage();
} else {
- emit(state.copyWith(missingInformation: true));
+ safeEmit(state.copyWith(missingInformation: true));
}
}
@@ -172,11 +172,11 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
phoneNumber: phoneNumber,
nationality: selectedNationality,
);
- emit(state.copyWith(user: updatedUser));
+ safeEmit(state.copyWith(user: updatedUser));
_navigateNextPage();
} else {
- emit(state.copyWith(missingInformation: true));
+ safeEmit(state.copyWith(missingInformation: true));
}
}
@@ -203,7 +203,7 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
}
void onPaymentMethodSelected(StoredPaymentMethod paymentMethod) {
- emit(
+ safeEmit(
state.copyWith(
selectedPaymentMethod: paymentMethod,
missingInformation: false,
@@ -225,7 +225,7 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
}
void _onConfirmPressed(BuildContext context) async {
- emit(state.copyWith(isLoading: true));
+ safeEmit(state.copyWith(isLoading: true));
try {
// Build the PreregRequestModel with all required fields
final String? sendIdType = isFavoriteCountry ? null : selectedDocumentType.code;
@@ -268,17 +268,18 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
if (preRegResponse != null) {
Future.delayed(const Duration(seconds: 3), () {
- emit(state.copyWith(isLoading: false));
+ safeEmit(state.copyWith(isLoading: false));
if (!context.mounted) return;
context.pop(preRegResponse);
});
} else {
- emit(state.copyWith(error: AppError.unknown('Pre-registration failed'), isLoading: false));
+ safeEmit(state.copyWith(error: AppError.unknown('Pre-registration failed'), isLoading: false));
if (!context.mounted) return;
context.pop(null);
}
- } catch (e) {
- emit(state.copyWith(error: AppError.unknown(e.toString()), isLoading: false));
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString()), isLoading: false));
}
}
@@ -296,27 +297,27 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
void onPhoneNumberChanged(String phoneNumber) {
phoneNumberTextController.text = phoneNumber;
- emit(state.copyWith(isPhoneNumberValid: isPhoneNumberValid));
+ safeEmit(state.copyWith(isPhoneNumberValid: isPhoneNumberValid));
}
void onCountryCodeSelected(CountryCode country) {
countryCode = country;
- emit(state.copyWith(countryCode: country, selectedCountry: country.code ?? ''));
+ safeEmit(state.copyWith(countryCode: country, selectedCountry: country.code ?? ''));
}
void onNationalitySelected(String nationality) {
selectedNationality = nationality;
- emit(state.copyWith(selectedNationality: selectedNationality));
+ safeEmit(state.copyWith(selectedNationality: selectedNationality));
}
void onSelectedCountrySelected(String country) {
selectedCountry = country;
- emit(state.copyWith(selectedCountry: country));
+ safeEmit(state.copyWith(selectedCountry: country));
}
Future<void> onBirthDateSelected(DateTime date) async {
final updatedUser = state.user!.copyWith(birthDate: date);
- emit(state.copyWith(user: updatedUser));
+ safeEmit(state.copyWith(user: updatedUser));
}
bool onBackClicked() {
@@ -337,7 +338,7 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
duration: const Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
);
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
_isAnimating = false;
}
@@ -348,7 +349,7 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
duration: const Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
);
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
_isAnimating = false;
}
@@ -359,7 +360,7 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
duration: const Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
);
- emit(state.copyWith(forceUpdate: !state.forceUpdate));
+ safeEmit(state.copyWith(forceUpdate: !state.forceUpdate));
_isAnimating = false;
}
diff --git a/comwell_key_app/lib/push_notifications/cubit/push_notification_cubit.dart b/comwell_key_app/lib/push_notifications/cubit/push_notification_cubit.dart
index a0cb52ee..0d6ebcfe 100644
--- a/comwell_key_app/lib/push_notifications/cubit/push_notification_cubit.dart
+++ b/comwell_key_app/lib/push_notifications/cubit/push_notification_cubit.dart
@@ -1,13 +1,13 @@
import 'dart:io';
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/push_notifications/cubit/push_notification_state.dart';
import 'package:comwell_key_app/push_notifications/push_notification_repository.dart';
import 'package:comwell_key_app/utils/locator.dart';
import 'package:flutter/widgets.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
-class PushNotificationCubit extends Cubit<PushNotificationState> {
+class PushNotificationCubit extends BaseCubit<PushNotificationState> {
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
final PushNotificationRepository pushNotificationRepository =
locator<PushNotificationRepository>();
@@ -33,32 +33,32 @@ class PushNotificationCubit extends Cubit<PushNotificationState> {
if (Platform.isIOS) {
// Re-read APNs token alongside refreshed FCM token
refreshedApnsToken = await _firebaseMessaging.getAPNSToken();
-
+
debugPrint('APNs Token (refreshed): $refreshedApnsToken');
-
+
}
debugPrint('FCM Token (refreshed): $newToken');
- emit(state.copyWith(fcmToken: newToken, apnsToken: refreshedApnsToken));
+ safeEmit(state.copyWith(fcmToken: newToken, apnsToken: refreshedApnsToken));
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
debugPrint('Message data: ${message.data}');
if (message.notification != null) {
- emit(state.copyWith(message: message.notification?.title));
+ safeEmit(state.copyWith(message: message.notification?.title));
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
- emit(state.copyWith(message: message.notification?.title));
+ safeEmit(state.copyWith(message: message.notification?.title));
});
- } catch (e) {
- debugPrint('Error: $e');
- emit(state.copyWith(error: e.toString()));
+ } catch (e, st) {
+ logError(e, st);
+ safeEmit(state.copyWith(error: e.toString()));
}
}
Future<void> registerPushTokenToSymplify() async {
await pushNotificationRepository.registerDeviceAndProfile(state.fcmToken ?? '');
-
+
}
Future<void> getFcmToken() async {
@@ -72,7 +72,7 @@ class PushNotificationCubit extends Cubit<PushNotificationState> {
final String? fcmToken = await _firebaseMessaging.getToken();
debugPrint('FCM Token: $fcmToken');
- emit(state.copyWith(fcmToken: fcmToken, apnsToken: apnsToken));
+ safeEmit(state.copyWith(fcmToken: fcmToken, apnsToken: apnsToken));
}
Future<void> getApnsToken() async {
@@ -83,6 +83,6 @@ class PushNotificationCubit extends Cubit<PushNotificationState> {
apnsToken = await _firebaseMessaging.getAPNSToken();
debugPrint('APNs Token: $apnsToken');
}
- emit(state.copyWith(apnsToken: apnsToken));
+ safeEmit(state.copyWith(apnsToken: apnsToken));
}
}
diff --git a/comwell_key_app/lib/share/cubit/share_booking_cubit.dart b/comwell_key_app/lib/share/cubit/share_booking_cubit.dart
index d1052058..7da7c2c6 100644
--- a/comwell_key_app/lib/share/cubit/share_booking_cubit.dart
+++ b/comwell_key_app/lib/share/cubit/share_booking_cubit.dart
@@ -1,16 +1,15 @@
-import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/base/base_cubit.dart';
import 'package:comwell_key_app/overview/models/guest.dart';
import 'package:comwell_key_app/share/share_booking_repository.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:equatable/equatable.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:flutter/material.dart';
-import 'package:intl/intl.dart';
import 'package:share_plus/share_plus.dart';
part 'share_booking_state.dart';
-class ShareBookingCubit extends Cubit<ShareBookingState> {
+class ShareBookingCubit extends BaseCubit<ShareBookingState> {
final ShareBookingRepository _shareBookingRepository;
final Booking booking;
@@ -19,17 +18,17 @@ class ShareBookingCubit extends Cubit<ShareBookingState> {
: super(const ShareBookingState.initial());
void updateSelectedGuests(Iterable<Guest> guests) {
- emit(state.updateSelectedGuests(guests));
+ safeEmit(state.updateSelectedGuests(guests));
}
void removeGuests(List<int> guestIds) {
final newSelectedGuests = state.selectedGuests.toList();
newSelectedGuests.removeWhere((guest) => guestIds.contains(guest.id));
- emit(state.updateSelectedGuests(newSelectedGuests));
+ safeEmit(state.updateSelectedGuests(newSelectedGuests));
}
Future<void> createRoomSharingLink(BuildContext context, Booking booking) async {
- emit(state.loading());
+ safeEmit(state.loading());
final link = await _shareBookingRepository.createRoomSharingLink(
booking.confirmationNumber,
@@ -46,9 +45,9 @@ class ShareBookingCubit extends Cubit<ShareBookingState> {
),
subject: context.strings.comwell_booking,
);
- emit(state.loaded());
+ safeEmit(state.loaded());
} else {
- emit(state.setupError(StateError('share_link_creation_failed')));
+ safeEmit(state.setupError(StateError('share_link_creation_failed')));
}
}
@@ -64,6 +63,6 @@ class ShareBookingCubit extends Cubit<ShareBookingState> {
}
void clearSelection() {
- emit(const ShareBookingState.initial());
+ safeEmit(const ShareBookingState.initial());
}
}
diff --git a/comwell_key_app/lib/up_sales/cubit/up_sales_cubit.dart b/comwell_key_app/lib/up_sales/cubit/up_sales_cubit.dart
index e6ab5b00..533f916c 100644
--- a/comwell_key_app/lib/up_sales/cubit/up_sales_cubit.dart
+++ b/comwell_key_app/lib/up_sales/cubit/up_sales_cubit.dart
@@ -39,8 +39,8 @@ class UpSalesCubit extends BaseCubit<UpSalesState> {
);
try {
safeEmit(state.loaded(upSales: upSales));
- } catch (e) {
- logError(e, StackTrace.current);
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.setupError(error: Exception(e)));
}
}
@@ -105,8 +105,8 @@ class UpSalesCubit extends BaseCubit<UpSalesState> {
);
await Future<void>.delayed(const Duration(seconds: 2));
safeEmit(state.processingStateUpdated(UpSalesProcessingStateSuccess()));
- } catch (e) {
- logError(e, StackTrace.current);
+ } catch (e, st) {
+ logError(e, st);
safeEmit(state.processingStateUpdated(UpSalesProcessingStateError()));
}
}