create order
This commit is contained in:
@@ -3,10 +3,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../../../application/order/order_form/order_form_bloc.dart';
|
||||
import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/spaces/space.dart';
|
||||
import '../../components/toast/flushbar.dart';
|
||||
import 'widgets/checkout_left_panel.dart';
|
||||
import 'widgets/checkout_right_panel.dart';
|
||||
|
||||
@@ -16,43 +18,56 @@ class CheckoutPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return 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,
|
||||
);
|
||||
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,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.white,
|
||||
body: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: CheckoutLeftPanel(
|
||||
checkoutState: state,
|
||||
price: price,
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.white,
|
||||
body: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: CheckoutLeftPanel(
|
||||
checkoutState: state,
|
||||
price: price,
|
||||
),
|
||||
),
|
||||
),
|
||||
SpaceWidth(2),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: CheckoutRightPanel(
|
||||
checkoutState: state,
|
||||
price: price,
|
||||
SpaceWidth(2),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: CheckoutRightPanel(
|
||||
checkoutState: state,
|
||||
price: price,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -304,26 +304,27 @@ class _CheckoutRightPanelState extends State<CheckoutRightPanel> {
|
||||
SpaceWidth(12),
|
||||
Expanded(
|
||||
child: AppElevatedButton.filled(
|
||||
onPressed: () {
|
||||
if (customerController.text == '') {
|
||||
AppFlushbar.showError(
|
||||
context,
|
||||
'Pilih Pelanggan terlebih dahulu',
|
||||
);
|
||||
return;
|
||||
}
|
||||
isLoading: orderState.isCreating,
|
||||
onPressed: orderState.isCreating
|
||||
? null
|
||||
: () {
|
||||
if (customerController.text == '') {
|
||||
AppFlushbar.showError(
|
||||
context,
|
||||
'Pilih Pelanggan terlebih dahulu',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
context.read<OrderFormBloc>().add(
|
||||
OrderFormEvent.createOrderWithPayment(
|
||||
items: widget.checkoutState.items,
|
||||
orderType: widget.checkoutState.orderType,
|
||||
table: widget.checkoutState.table,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
// context.read<OrderFormBloc>().add(
|
||||
// OrderFormEvent.createWithPayment(
|
||||
// items: items,
|
||||
// customerName: customerController.text,
|
||||
// orderType: orderType,
|
||||
// paymentMethod: selectedPaymentMethod!,
|
||||
// table: widget.table,
|
||||
// customer: selectedCustomer,
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
label: 'Bayar',
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user