6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 7a90b31c

AuthorEdmir Suljic<esu@dwarf.dk>
Date2026-02-27 15:14:15 +0100
checkout bug fixes

Changed files

.../lib/check_out/bloc/check_out_state.dart        | 12 ++-
 comwell_key_app/lib/check_out/check_out_flow.dart  |  2 +-
 comwell_key_app/lib/check_out/checkout_routes.dart | 24 +++++-
 .../lib/check_out/pages/check_out_error_page.dart  | 95 ++++++++++++----------
 .../check_out/pages/check_out_processing_page.dart | 11 +--
 5 files changed, 87 insertions(+), 57 deletions(-)

Diff

diff --git a/comwell_key_app/lib/check_out/bloc/check_out_state.dart b/comwell_key_app/lib/check_out/bloc/check_out_state.dart
index e11fe4a9..1a044747 100644
--- a/comwell_key_app/lib/check_out/bloc/check_out_state.dart
+++ b/comwell_key_app/lib/check_out/bloc/check_out_state.dart
@@ -15,6 +15,7 @@ class CheckoutState extends Equatable {
final num bookingBalance;
final bool isPaymentProcessingNeeded;
final bool isLoading;
+ final bool hasCheckoutError;
int get totalPriceBeforeDiscount => _sumOfList(_items);
@@ -50,6 +51,7 @@ class CheckoutState extends Equatable {
required this.successfulCheckout,
required this.isPaymentProcessingNeeded,
required this.isLoading,
+ required this.hasCheckoutError,
}) : _items = items;
CheckoutState.initial(this.bookingBalance)
@@ -62,7 +64,8 @@ class CheckoutState extends Equatable {
applyClubPoints = false,
successfulCheckout = false,
isLoading = false,
- isPaymentProcessingNeeded = true;
+ isPaymentProcessingNeeded = true,
+ hasCheckoutError = false;
CheckoutState itemsUpdated(Iterable<BookingAddonItem> items) {
final newItems = <BookingAddonItem>[];
@@ -93,9 +96,9 @@ class CheckoutState extends Equatable {
CheckoutState showAcceptTermsError() => _copyWith(showTermsError: true);
- CheckoutState checkoutSuccess() => _copyWith(successfulCheckout: true);
+ CheckoutState checkoutSuccess() => _copyWith(successfulCheckout: true, hasCheckoutError: false);
- CheckoutState checkoutError() => _copyWith(successfulCheckout: false);
+ CheckoutState checkoutError() => _copyWith(successfulCheckout: false, hasCheckoutError: true);
CheckoutState paymentProcessingNeeded() => _copyWith(isPaymentProcessingNeeded: true);
@@ -113,6 +116,7 @@ class CheckoutState extends Equatable {
bool? successfulCheckout,
bool? isPaymentProcessingNeeded,
bool? isLoading,
+ bool? hasCheckoutError,
}) {
return CheckoutState(
items: items ?? _items,
@@ -126,6 +130,7 @@ class CheckoutState extends Equatable {
successfulCheckout: successfulCheckout ?? this.successfulCheckout,
isPaymentProcessingNeeded: isPaymentProcessingNeeded ?? this.isPaymentProcessingNeeded,
isLoading: isLoading ?? this.isLoading,
+ hasCheckoutError: hasCheckoutError ?? this.hasCheckoutError,
);
}
@@ -143,5 +148,6 @@ class CheckoutState extends Equatable {
successfulCheckout,
isPaymentProcessingNeeded,
isLoading,
+ hasCheckoutError,
];
}
diff --git a/comwell_key_app/lib/check_out/check_out_flow.dart b/comwell_key_app/lib/check_out/check_out_flow.dart
index effa50f8..59158df0 100644
--- a/comwell_key_app/lib/check_out/check_out_flow.dart
+++ b/comwell_key_app/lib/check_out/check_out_flow.dart
@@ -28,7 +28,7 @@ class CheckOutFlow extends StatelessWidget {
await cubit.checkOut();
if (cubit.state.successfulCheckout && context.mounted) {
context.push(AppRoutes.checkOutSuccess, extra: cubit.booking.digitalCard);
- } else if (context.mounted) {
+ } else if (cubit.state.hasCheckoutError && context.mounted) {
context.push(AppRoutes.checkOutError);
}
}
diff --git a/comwell_key_app/lib/check_out/checkout_routes.dart b/comwell_key_app/lib/check_out/checkout_routes.dart
index 7d53f840..119080a6 100644
--- a/comwell_key_app/lib/check_out/checkout_routes.dart
+++ b/comwell_key_app/lib/check_out/checkout_routes.dart
@@ -14,14 +14,32 @@ final checkOutRoutes = [_checkOutError, _checkOutSuccess, _checkOutFlow];
final _checkOutError = GoRoute(
path: AppRoutes.checkOutError,
- builder: (context, state) => const CheckOutErrorPage(),
+ builder: (context, state) {
+ return BlocProvider(
+ create: (context) => CheckoutCubit(state.extra as Booking, locator(), context.read()),
+ child: BlocBuilder<CheckoutCubit, CheckoutState>(
+ builder: (context, state) {
+ return CheckOutErrorPage(key: ValueKey(state));
+ },
+ ),
+ );
+ },
);
final _checkOutSuccess = GoRoute(
path: AppRoutes.checkOutSuccess,
builder: (context, state) {
- final digitalCard = state.extra as bool;
- return CheckOutSuccessPage(digitalCard: digitalCard);
+ final extras = state.extra as List<dynamic>;
+ final digitalCard = extras[0] as bool;
+ final booking = extras[1] as Booking;
+ return BlocProvider(
+ create: (context) => CheckoutCubit(booking, locator(), context.read()),
+ child: BlocBuilder<CheckoutCubit, CheckoutState>(
+ builder: (context, state) {
+ return CheckOutSuccessPage(digitalCard: digitalCard, key: ValueKey(state));
+ },
+ ),
+ );
},
);
diff --git a/comwell_key_app/lib/check_out/pages/check_out_error_page.dart b/comwell_key_app/lib/check_out/pages/check_out_error_page.dart
index f4baca15..7fcc8813 100644
--- a/comwell_key_app/lib/check_out/pages/check_out_error_page.dart
+++ b/comwell_key_app/lib/check_out/pages/check_out_error_page.dart
@@ -1,4 +1,5 @@
import 'package:comwell_key_app/check_out/bloc/check_out_cubit.dart';
+import 'package:comwell_key_app/check_out/bloc/check_out_state.dart';
import 'package:comwell_key_app/routing/app_routes.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
@@ -11,59 +12,63 @@ class CheckOutErrorPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final cubit = context.read<CheckoutCubit>();
- return Scaffold(
- backgroundColor: sandColor[80],
- body: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0),
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 40.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- const SizedBox(),
- Column(
+ return BlocBuilder<CheckoutCubit, CheckoutState>(
+ builder: (context, state) {
+ final cubit = context.read<CheckoutCubit>();
+ return Scaffold(
+ backgroundColor: sandColor[80],
+ body: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 40.0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
- Text(
- context.strings.checkout_page_processing_error_title,
- style: Theme.of(
- context,
- ).textTheme.headlineMedium?.copyWith(color: colorBackground),
- ),
- Text(
- context.strings.checkout_page_processing_error_subtitle,
- textAlign: TextAlign.center,
- style: Theme.of(context).textTheme.bodySmall?.copyWith(color: colorDivider),
- ),
- ],
- ),
- Row(
- children: [
- Expanded(
- child: ElevatedButton(
- onPressed: () {
- context.go(AppRoutes.overview);
- context.push(AppRoutes.bookingDetails, extra: cubit.booking);
- },
- style: const ButtonStyle(
- backgroundColor: WidgetStatePropertyAll(colorBackground),
+ const SizedBox(),
+ Column(
+ children: [
+ Text(
+ context.strings.checkout_page_processing_error_title,
+ style: Theme.of(
+ context,
+ ).textTheme.headlineMedium?.copyWith(color: colorBackground),
+ ),
+ Text(
+ context.strings.checkout_page_processing_error_subtitle,
+ textAlign: TextAlign.center,
+ style: Theme.of(context).textTheme.bodySmall?.copyWith(color: colorDivider),
),
- child: Padding(
- padding: const EdgeInsets.all(16.0),
- child: Text(
- context.strings.generic_ok,
- style: const TextStyle(color: colorTertiary),
+ ],
+ ),
+ Row(
+ children: [
+ Expanded(
+ child: ElevatedButton(
+ onPressed: () {
+ context.go(AppRoutes.overview);
+ context.push(AppRoutes.bookingDetails, extra: cubit.booking);
+ },
+ style: const ButtonStyle(
+ backgroundColor: WidgetStatePropertyAll(colorBackground),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(16.0),
+ child: Text(
+ context.strings.generic_ok,
+ style: const TextStyle(color: colorTertiary),
+ ),
+ ),
),
),
- ),
+ ],
),
],
),
- ],
+ ),
),
- ),
- ),
+ );
+ },
);
}
}
diff --git a/comwell_key_app/lib/check_out/pages/check_out_processing_page.dart b/comwell_key_app/lib/check_out/pages/check_out_processing_page.dart
index 9d82df17..67f195f7 100644
--- a/comwell_key_app/lib/check_out/pages/check_out_processing_page.dart
+++ b/comwell_key_app/lib/check_out/pages/check_out_processing_page.dart
@@ -69,13 +69,14 @@ class _CheckOutProcessingPageState extends State<CheckOutProcessingPage>
Widget build(BuildContext context) {
final cubit = context.read<CheckoutCubit>();
return BlocListener<CheckoutCubit, CheckoutState>(
- listenWhen: (previous, current) => previous.successfulCheckout != current.successfulCheckout,
+ listenWhen: (previous, current) =>
+ previous.successfulCheckout != current.successfulCheckout ||
+ previous.hasCheckoutError != current.hasCheckoutError,
listener: (context, state) {
if (state.successfulCheckout) {
- context.push(AppRoutes.checkOutSuccess,
- extra: cubit.booking.digitalCard);
- } else {
- context.push(AppRoutes.checkOutError);
+ context.push(AppRoutes.checkOutSuccess, extra: cubit.booking.digitalCard);
+ } else if (state.hasCheckoutError) {
+ context.push(AppRoutes.checkOutError, extra: cubit.booking);
}
},
child: Scaffold(