2025-10-27 01:54:35 +07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
2025-10-28 00:08:12 +07:00
|
|
|
import '../../../application/order/order_form/order_form_bloc.dart';
|
2025-10-27 14:24:29 +07:00
|
|
|
import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
2025-10-27 01:54:35 +07:00
|
|
|
import '../../../common/theme/theme.dart';
|
2025-10-27 14:24:29 +07:00
|
|
|
import '../../../injection.dart';
|
2025-10-27 01:54:35 +07:00
|
|
|
import '../../components/spaces/space.dart';
|
2025-10-28 00:08:12 +07:00
|
|
|
import '../../components/toast/flushbar.dart';
|
2025-10-27 01:54:35 +07:00
|
|
|
import 'widgets/checkout_left_panel.dart';
|
|
|
|
|
import 'widgets/checkout_right_panel.dart';
|
|
|
|
|
|
|
|
|
|
@RoutePage()
|
2025-10-27 14:24:29 +07:00
|
|
|
class CheckoutPage extends StatelessWidget implements AutoRouteWrapper {
|
2025-10-27 01:54:35 +07:00
|
|
|
const CheckoutPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-10-28 00:08:12 +07:00
|
|
|
return BlocListener<OrderFormBloc, OrderFormState>(
|
|
|
|
|
listenWhen: (previous, current) =>
|
|
|
|
|
previous.failureOrCreateOrder != current.failureOrCreateOrder,
|
|
|
|
|
listener: (context, state) {
|
|
|
|
|
state.failureOrCreateOrder.fold(() {}, (either) {
|
|
|
|
|
either.fold((f) => AppFlushbar.showOrderFailureToast(context, f), (
|
|
|
|
|
order,
|
|
|
|
|
) {
|
|
|
|
|
if (context.mounted) {}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
child: Hero(
|
|
|
|
|
tag: 'checkout_screen',
|
|
|
|
|
child: BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
final price = state.items.fold(
|
|
|
|
|
0,
|
|
|
|
|
(previousValue, element) =>
|
|
|
|
|
previousValue +
|
|
|
|
|
(element.product.price.toInt() +
|
|
|
|
|
(element.variant?.priceModifier.toInt() ?? 0)) *
|
|
|
|
|
element.quantity,
|
|
|
|
|
);
|
2025-10-27 01:54:35 +07:00
|
|
|
|
2025-10-28 00:08:12 +07:00
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: AppColor.white,
|
|
|
|
|
body: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 3,
|
|
|
|
|
child: CheckoutLeftPanel(
|
|
|
|
|
checkoutState: state,
|
|
|
|
|
price: price,
|
|
|
|
|
),
|
2025-10-27 01:54:35 +07:00
|
|
|
),
|
2025-10-28 00:08:12 +07:00
|
|
|
SpaceWidth(2),
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 3,
|
|
|
|
|
child: CheckoutRightPanel(
|
|
|
|
|
checkoutState: state,
|
|
|
|
|
price: price,
|
|
|
|
|
),
|
2025-10-27 15:27:21 +07:00
|
|
|
),
|
2025-10-28 00:08:12 +07:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2025-10-27 01:54:35 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-10-27 14:24:29 +07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
|
|
|
|
create: (context) =>
|
|
|
|
|
getIt<PaymentMethodLoaderBloc>()
|
|
|
|
|
..add(PaymentMethodLoaderEvent.fetched(isRefresh: true)),
|
|
|
|
|
child: this,
|
|
|
|
|
);
|
2025-10-27 01:54:35 +07:00
|
|
|
}
|