From 617b5c54f2b071e05a6415e1895217aa29f1f24f Mon Sep 17 00:00:00 2001 From: efrilm Date: Sun, 3 Aug 2025 22:44:01 +0700 Subject: [PATCH] feat: select order item --- .../home/bloc/order_form/order_form_bloc.dart | 60 + .../order_form/order_form_bloc.freezed.dart | 1112 ++++++++++++++++- .../bloc/order_form/order_form_event.dart | 5 + .../bloc/order_form/order_form_state.dart | 5 + lib/presentation/home/pages/home_page.dart | 5 +- lib/presentation/sales/pages/sales_page.dart | 4 + .../sales/widgets/sales_list_order.dart | 133 +- 7 files changed, 1220 insertions(+), 104 deletions(-) diff --git a/lib/presentation/home/bloc/order_form/order_form_bloc.dart b/lib/presentation/home/bloc/order_form/order_form_bloc.dart index a032b8c..4326d7b 100644 --- a/lib/presentation/home/bloc/order_form/order_form_bloc.dart +++ b/lib/presentation/home/bloc/order_form/order_form_bloc.dart @@ -17,6 +17,9 @@ part 'order_form_bloc.freezed.dart'; class OrderFormBloc extends Bloc { final OrderRemoteDatasource _orderRemoteDatasource; OrderFormBloc(this._orderRemoteDatasource) : super(OrderFormState.initial()) { + on<_Started>((event, emit) { + emit(OrderFormState.loaded(order: event.order)); + }); on<_Create>( (event, emit) async { emit(const _Loading()); @@ -100,5 +103,62 @@ class OrderFormBloc extends Bloc { } }, ); + on<_ToggleItem>((event, emit) { + state.maybeWhen( + loaded: (order, selectedItems, _) { + final newList = [...selectedItems]; + final exists = newList.any((e) => e.id == event.item.id); + + if (exists) { + newList.removeWhere((e) => e.id == event.item.id); + } else { + newList.add(event.item); + } + + final isAll = newList.length == (order.orderItems?.length ?? 0); + + emit(OrderFormState.loaded( + order: order, + selectedItems: newList, + isAllSelected: isAll, + )); + }, + orElse: () {}, + ); + }); + + on<_ToggleSelectAll>((event, emit) { + state.maybeWhen( + loaded: (order, _, __) { + final items = event.selectAll + ? (order.orderItems ?? []) + : []; + + emit(OrderFormState.loaded( + order: order, + selectedItems: items, + isAllSelected: event.selectAll, + )); + }, + orElse: () {}, + ); + }); + + on<_Refund>((event, emit) async { + state.maybeWhen( + loaded: (order, selectedItems, _) async { + if (selectedItems.isEmpty) return; + + emit(const OrderFormState.loading()); + + try { + emit(OrderFormState.success(order)); + } catch (e) { + emit(OrderFormState.error('Refund gagal: ${e.toString()}')); + } + }, + orElse: () {}, + ); + }); } } diff --git a/lib/presentation/home/bloc/order_form/order_form_bloc.freezed.dart b/lib/presentation/home/bloc/order_form/order_form_bloc.freezed.dart index e9b4339..aea6985 100644 --- a/lib/presentation/home/bloc/order_form/order_form_bloc.freezed.dart +++ b/lib/presentation/home/bloc/order_form/order_form_bloc.freezed.dart @@ -16,12 +16,9 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$OrderFormEvent { - List get items => throw _privateConstructorUsedError; - String get customerName => throw _privateConstructorUsedError; - OrderType get orderType => throw _privateConstructorUsedError; - String get tableNumber => throw _privateConstructorUsedError; @optionalTypeArgs TResult when({ + required TResult Function(Order order) started, required TResult Function(List items, String customerName, OrderType orderType, String tableNumber) create, @@ -32,10 +29,14 @@ mixin _$OrderFormEvent { String tableNumber, PaymentMethod paymentMethod) createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ + TResult? Function(Order order)? started, TResult? Function(List items, String customerName, OrderType orderType, String tableNumber)? create, @@ -46,10 +47,14 @@ mixin _$OrderFormEvent { String tableNumber, PaymentMethod paymentMethod)? createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ + TResult Function(Order order)? started, TResult Function(List items, String customerName, OrderType orderType, String tableNumber)? create, @@ -60,34 +65,43 @@ mixin _$OrderFormEvent { String tableNumber, PaymentMethod paymentMethod)? createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult map({ + required TResult Function(_Started value) started, required TResult Function(_Create value) create, required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ + TResult? Function(_Started value)? started, TResult? Function(_Create value)? create, TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ + TResult Function(_Started value)? started, TResult Function(_Create value)? create, TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, required TResult orElse(), }) => throw _privateConstructorUsedError; - - /// Create a copy of OrderFormEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $OrderFormEventCopyWith get copyWith => - throw _privateConstructorUsedError; } /// @nodoc @@ -95,12 +109,6 @@ abstract class $OrderFormEventCopyWith<$Res> { factory $OrderFormEventCopyWith( OrderFormEvent value, $Res Function(OrderFormEvent) then) = _$OrderFormEventCopyWithImpl<$Res, OrderFormEvent>; - @useResult - $Res call( - {List items, - String customerName, - OrderType orderType, - String tableNumber}); } /// @nodoc @@ -113,44 +121,203 @@ class _$OrderFormEventCopyWithImpl<$Res, $Val extends OrderFormEvent> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$StartedImplCopyWith<$Res> { + factory _$$StartedImplCopyWith( + _$StartedImpl value, $Res Function(_$StartedImpl) then) = + __$$StartedImplCopyWithImpl<$Res>; + @useResult + $Res call({Order order}); +} + +/// @nodoc +class __$$StartedImplCopyWithImpl<$Res> + extends _$OrderFormEventCopyWithImpl<$Res, _$StartedImpl> + implements _$$StartedImplCopyWith<$Res> { + __$$StartedImplCopyWithImpl( + _$StartedImpl _value, $Res Function(_$StartedImpl) _then) + : super(_value, _then); + /// Create a copy of OrderFormEvent /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ - Object? items = null, - Object? customerName = null, - Object? orderType = null, - Object? tableNumber = null, + Object? order = null, }) { - return _then(_value.copyWith( - items: null == items - ? _value.items - : items // ignore: cast_nullable_to_non_nullable - as List, - customerName: null == customerName - ? _value.customerName - : customerName // ignore: cast_nullable_to_non_nullable - as String, - orderType: null == orderType - ? _value.orderType - : orderType // ignore: cast_nullable_to_non_nullable - as OrderType, - tableNumber: null == tableNumber - ? _value.tableNumber - : tableNumber // ignore: cast_nullable_to_non_nullable - as String, - ) as $Val); + return _then(_$StartedImpl( + null == order + ? _value.order + : order // ignore: cast_nullable_to_non_nullable + as Order, + )); } } /// @nodoc -abstract class _$$CreateImplCopyWith<$Res> - implements $OrderFormEventCopyWith<$Res> { + +class _$StartedImpl implements _Started { + const _$StartedImpl(this.order); + + @override + final Order order; + + @override + String toString() { + return 'OrderFormEvent.started(order: $order)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$StartedImpl && + (identical(other.order, order) || other.order == order)); + } + + @override + int get hashCode => Object.hash(runtimeType, order); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$StartedImplCopyWith<_$StartedImpl> get copyWith => + __$$StartedImplCopyWithImpl<_$StartedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Order order) started, + required TResult Function(List items, String customerName, + OrderType orderType, String tableNumber) + create, + required TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod) + createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, + }) { + return started(order); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(Order order)? started, + TResult? Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult? Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, + }) { + return started?.call(order); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Order order)? started, + TResult Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, + required TResult orElse(), + }) { + if (started != null) { + return started(order); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(_Create value) create, + required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, + }) { + return started(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Started value)? started, + TResult? Function(_Create value)? create, + TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, + }) { + return started?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(_Create value)? create, + TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, + required TResult orElse(), + }) { + if (started != null) { + return started(this); + } + return orElse(); + } +} + +abstract class _Started implements OrderFormEvent { + const factory _Started(final Order order) = _$StartedImpl; + + Order get order; + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$StartedImplCopyWith<_$StartedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$CreateImplCopyWith<$Res> { factory _$$CreateImplCopyWith( _$CreateImpl value, $Res Function(_$CreateImpl) then) = __$$CreateImplCopyWithImpl<$Res>; - @override @useResult $Res call( {List items, @@ -261,6 +428,7 @@ class _$CreateImpl implements _Create { @override @optionalTypeArgs TResult when({ + required TResult Function(Order order) started, required TResult Function(List items, String customerName, OrderType orderType, String tableNumber) create, @@ -271,6 +439,9 @@ class _$CreateImpl implements _Create { String tableNumber, PaymentMethod paymentMethod) createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, }) { return create(items, customerName, orderType, tableNumber); } @@ -278,6 +449,7 @@ class _$CreateImpl implements _Create { @override @optionalTypeArgs TResult? whenOrNull({ + TResult? Function(Order order)? started, TResult? Function(List items, String customerName, OrderType orderType, String tableNumber)? create, @@ -288,6 +460,9 @@ class _$CreateImpl implements _Create { String tableNumber, PaymentMethod paymentMethod)? createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, }) { return create?.call(items, customerName, orderType, tableNumber); } @@ -295,6 +470,7 @@ class _$CreateImpl implements _Create { @override @optionalTypeArgs TResult maybeWhen({ + TResult Function(Order order)? started, TResult Function(List items, String customerName, OrderType orderType, String tableNumber)? create, @@ -305,6 +481,9 @@ class _$CreateImpl implements _Create { String tableNumber, PaymentMethod paymentMethod)? createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, required TResult orElse(), }) { if (create != null) { @@ -316,8 +495,12 @@ class _$CreateImpl implements _Create { @override @optionalTypeArgs TResult map({ + required TResult Function(_Started value) started, required TResult Function(_Create value) create, required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, }) { return create(this); } @@ -325,8 +508,12 @@ class _$CreateImpl implements _Create { @override @optionalTypeArgs TResult? mapOrNull({ + TResult? Function(_Started value)? started, TResult? Function(_Create value)? create, TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, }) { return create?.call(this); } @@ -334,8 +521,12 @@ class _$CreateImpl implements _Create { @override @optionalTypeArgs TResult maybeMap({ + TResult Function(_Started value)? started, TResult Function(_Create value)? create, TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, required TResult orElse(), }) { if (create != null) { @@ -352,31 +543,24 @@ abstract class _Create implements OrderFormEvent { required final OrderType orderType, required final String tableNumber}) = _$CreateImpl; - @override List get items; - @override String get customerName; - @override OrderType get orderType; - @override String get tableNumber; /// Create a copy of OrderFormEvent /// with the given fields replaced by the non-null parameter values. - @override @JsonKey(includeFromJson: false, includeToJson: false) _$$CreateImplCopyWith<_$CreateImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$CreateWithPaymentMethodImplCopyWith<$Res> - implements $OrderFormEventCopyWith<$Res> { +abstract class _$$CreateWithPaymentMethodImplCopyWith<$Res> { factory _$$CreateWithPaymentMethodImplCopyWith( _$CreateWithPaymentMethodImpl value, $Res Function(_$CreateWithPaymentMethodImpl) then) = __$$CreateWithPaymentMethodImplCopyWithImpl<$Res>; - @override @useResult $Res call( {List items, @@ -404,7 +588,7 @@ class __$$CreateWithPaymentMethodImplCopyWithImpl<$Res> Object? customerName = null, Object? orderType = null, Object? tableNumber = null, - Object? paymentMethod = freezed, + Object? paymentMethod = null, }) { return _then(_$CreateWithPaymentMethodImpl( items: null == items @@ -423,7 +607,7 @@ class __$$CreateWithPaymentMethodImplCopyWithImpl<$Res> ? _value.tableNumber : tableNumber // ignore: cast_nullable_to_non_nullable as String, - paymentMethod: freezed == paymentMethod + paymentMethod: null == paymentMethod ? _value.paymentMethod : paymentMethod // ignore: cast_nullable_to_non_nullable as PaymentMethod, @@ -476,8 +660,8 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { other.orderType == orderType) && (identical(other.tableNumber, tableNumber) || other.tableNumber == tableNumber) && - const DeepCollectionEquality() - .equals(other.paymentMethod, paymentMethod)); + (identical(other.paymentMethod, paymentMethod) || + other.paymentMethod == paymentMethod)); } @override @@ -487,7 +671,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { customerName, orderType, tableNumber, - const DeepCollectionEquality().hash(paymentMethod)); + paymentMethod); /// Create a copy of OrderFormEvent /// with the given fields replaced by the non-null parameter values. @@ -501,6 +685,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { @override @optionalTypeArgs TResult when({ + required TResult Function(Order order) started, required TResult Function(List items, String customerName, OrderType orderType, String tableNumber) create, @@ -511,6 +696,9 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { String tableNumber, PaymentMethod paymentMethod) createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, }) { return createWithPayment( items, customerName, orderType, tableNumber, paymentMethod); @@ -519,6 +707,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { @override @optionalTypeArgs TResult? whenOrNull({ + TResult? Function(Order order)? started, TResult? Function(List items, String customerName, OrderType orderType, String tableNumber)? create, @@ -529,6 +718,9 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { String tableNumber, PaymentMethod paymentMethod)? createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, }) { return createWithPayment?.call( items, customerName, orderType, tableNumber, paymentMethod); @@ -537,6 +729,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { @override @optionalTypeArgs TResult maybeWhen({ + TResult Function(Order order)? started, TResult Function(List items, String customerName, OrderType orderType, String tableNumber)? create, @@ -547,6 +740,9 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { String tableNumber, PaymentMethod paymentMethod)? createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, required TResult orElse(), }) { if (createWithPayment != null) { @@ -559,8 +755,12 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { @override @optionalTypeArgs TResult map({ + required TResult Function(_Started value) started, required TResult Function(_Create value) create, required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, }) { return createWithPayment(this); } @@ -568,8 +768,12 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { @override @optionalTypeArgs TResult? mapOrNull({ + TResult? Function(_Started value)? started, TResult? Function(_Create value)? create, TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, }) { return createWithPayment?.call(this); } @@ -577,8 +781,12 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod { @override @optionalTypeArgs TResult maybeMap({ + TResult Function(_Started value)? started, TResult Function(_Create value)? create, TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, required TResult orElse(), }) { if (createWithPayment != null) { @@ -597,30 +805,559 @@ abstract class _CreateWithPaymentMethod implements OrderFormEvent { required final PaymentMethod paymentMethod}) = _$CreateWithPaymentMethodImpl; - @override List get items; - @override String get customerName; - @override OrderType get orderType; - @override String get tableNumber; PaymentMethod get paymentMethod; /// Create a copy of OrderFormEvent /// with the given fields replaced by the non-null parameter values. - @override @JsonKey(includeFromJson: false, includeToJson: false) _$$CreateWithPaymentMethodImplCopyWith<_$CreateWithPaymentMethodImpl> get copyWith => throw _privateConstructorUsedError; } +/// @nodoc +abstract class _$$ToggleItemImplCopyWith<$Res> { + factory _$$ToggleItemImplCopyWith( + _$ToggleItemImpl value, $Res Function(_$ToggleItemImpl) then) = + __$$ToggleItemImplCopyWithImpl<$Res>; + @useResult + $Res call({OrderItem item}); +} + +/// @nodoc +class __$$ToggleItemImplCopyWithImpl<$Res> + extends _$OrderFormEventCopyWithImpl<$Res, _$ToggleItemImpl> + implements _$$ToggleItemImplCopyWith<$Res> { + __$$ToggleItemImplCopyWithImpl( + _$ToggleItemImpl _value, $Res Function(_$ToggleItemImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? item = null, + }) { + return _then(_$ToggleItemImpl( + null == item + ? _value.item + : item // ignore: cast_nullable_to_non_nullable + as OrderItem, + )); + } +} + +/// @nodoc + +class _$ToggleItemImpl implements _ToggleItem { + const _$ToggleItemImpl(this.item); + + @override + final OrderItem item; + + @override + String toString() { + return 'OrderFormEvent.toggleItem(item: $item)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ToggleItemImpl && + (identical(other.item, item) || other.item == item)); + } + + @override + int get hashCode => Object.hash(runtimeType, item); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ToggleItemImplCopyWith<_$ToggleItemImpl> get copyWith => + __$$ToggleItemImplCopyWithImpl<_$ToggleItemImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Order order) started, + required TResult Function(List items, String customerName, + OrderType orderType, String tableNumber) + create, + required TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod) + createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, + }) { + return toggleItem(item); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(Order order)? started, + TResult? Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult? Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, + }) { + return toggleItem?.call(item); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Order order)? started, + TResult Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, + required TResult orElse(), + }) { + if (toggleItem != null) { + return toggleItem(item); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(_Create value) create, + required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, + }) { + return toggleItem(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Started value)? started, + TResult? Function(_Create value)? create, + TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, + }) { + return toggleItem?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(_Create value)? create, + TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, + required TResult orElse(), + }) { + if (toggleItem != null) { + return toggleItem(this); + } + return orElse(); + } +} + +abstract class _ToggleItem implements OrderFormEvent { + const factory _ToggleItem(final OrderItem item) = _$ToggleItemImpl; + + OrderItem get item; + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ToggleItemImplCopyWith<_$ToggleItemImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$ToggleSelectAllImplCopyWith<$Res> { + factory _$$ToggleSelectAllImplCopyWith(_$ToggleSelectAllImpl value, + $Res Function(_$ToggleSelectAllImpl) then) = + __$$ToggleSelectAllImplCopyWithImpl<$Res>; + @useResult + $Res call({bool selectAll}); +} + +/// @nodoc +class __$$ToggleSelectAllImplCopyWithImpl<$Res> + extends _$OrderFormEventCopyWithImpl<$Res, _$ToggleSelectAllImpl> + implements _$$ToggleSelectAllImplCopyWith<$Res> { + __$$ToggleSelectAllImplCopyWithImpl( + _$ToggleSelectAllImpl _value, $Res Function(_$ToggleSelectAllImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? selectAll = null, + }) { + return _then(_$ToggleSelectAllImpl( + null == selectAll + ? _value.selectAll + : selectAll // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$ToggleSelectAllImpl implements _ToggleSelectAll { + const _$ToggleSelectAllImpl(this.selectAll); + + @override + final bool selectAll; + + @override + String toString() { + return 'OrderFormEvent.toggleSelectAll(selectAll: $selectAll)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ToggleSelectAllImpl && + (identical(other.selectAll, selectAll) || + other.selectAll == selectAll)); + } + + @override + int get hashCode => Object.hash(runtimeType, selectAll); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ToggleSelectAllImplCopyWith<_$ToggleSelectAllImpl> get copyWith => + __$$ToggleSelectAllImplCopyWithImpl<_$ToggleSelectAllImpl>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Order order) started, + required TResult Function(List items, String customerName, + OrderType orderType, String tableNumber) + create, + required TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod) + createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, + }) { + return toggleSelectAll(selectAll); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(Order order)? started, + TResult? Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult? Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, + }) { + return toggleSelectAll?.call(selectAll); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Order order)? started, + TResult Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, + required TResult orElse(), + }) { + if (toggleSelectAll != null) { + return toggleSelectAll(selectAll); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(_Create value) create, + required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, + }) { + return toggleSelectAll(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Started value)? started, + TResult? Function(_Create value)? create, + TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, + }) { + return toggleSelectAll?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(_Create value)? create, + TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, + required TResult orElse(), + }) { + if (toggleSelectAll != null) { + return toggleSelectAll(this); + } + return orElse(); + } +} + +abstract class _ToggleSelectAll implements OrderFormEvent { + const factory _ToggleSelectAll(final bool selectAll) = _$ToggleSelectAllImpl; + + bool get selectAll; + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ToggleSelectAllImplCopyWith<_$ToggleSelectAllImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$RefundImplCopyWith<$Res> { + factory _$$RefundImplCopyWith( + _$RefundImpl value, $Res Function(_$RefundImpl) then) = + __$$RefundImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$RefundImplCopyWithImpl<$Res> + extends _$OrderFormEventCopyWithImpl<$Res, _$RefundImpl> + implements _$$RefundImplCopyWith<$Res> { + __$$RefundImplCopyWithImpl( + _$RefundImpl _value, $Res Function(_$RefundImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$RefundImpl implements _Refund { + const _$RefundImpl(); + + @override + String toString() { + return 'OrderFormEvent.refund()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$RefundImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Order order) started, + required TResult Function(List items, String customerName, + OrderType orderType, String tableNumber) + create, + required TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod) + createWithPayment, + required TResult Function(OrderItem item) toggleItem, + required TResult Function(bool selectAll) toggleSelectAll, + required TResult Function() refund, + }) { + return refund(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(Order order)? started, + TResult? Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult? Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult? Function(OrderItem item)? toggleItem, + TResult? Function(bool selectAll)? toggleSelectAll, + TResult? Function()? refund, + }) { + return refund?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Order order)? started, + TResult Function(List items, String customerName, + OrderType orderType, String tableNumber)? + create, + TResult Function( + List items, + String customerName, + OrderType orderType, + String tableNumber, + PaymentMethod paymentMethod)? + createWithPayment, + TResult Function(OrderItem item)? toggleItem, + TResult Function(bool selectAll)? toggleSelectAll, + TResult Function()? refund, + required TResult orElse(), + }) { + if (refund != null) { + return refund(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(_Create value) create, + required TResult Function(_CreateWithPaymentMethod value) createWithPayment, + required TResult Function(_ToggleItem value) toggleItem, + required TResult Function(_ToggleSelectAll value) toggleSelectAll, + required TResult Function(_Refund value) refund, + }) { + return refund(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Started value)? started, + TResult? Function(_Create value)? create, + TResult? Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult? Function(_ToggleItem value)? toggleItem, + TResult? Function(_ToggleSelectAll value)? toggleSelectAll, + TResult? Function(_Refund value)? refund, + }) { + return refund?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(_Create value)? create, + TResult Function(_CreateWithPaymentMethod value)? createWithPayment, + TResult Function(_ToggleItem value)? toggleItem, + TResult Function(_ToggleSelectAll value)? toggleSelectAll, + TResult Function(_Refund value)? refund, + required TResult orElse(), + }) { + if (refund != null) { + return refund(this); + } + return orElse(); + } +} + +abstract class _Refund implements OrderFormEvent { + const factory _Refund() = _$RefundImpl; +} + /// @nodoc mixin _$OrderFormState { @optionalTypeArgs TResult when({ required TResult Function() initial, required TResult Function() loading, + required TResult Function( + Order order, List selectedItems, bool isAllSelected) + loaded, required TResult Function(Order order) success, required TResult Function(String message) error, }) => @@ -629,6 +1366,9 @@ mixin _$OrderFormState { TResult? whenOrNull({ TResult? Function()? initial, TResult? Function()? loading, + TResult? Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult? Function(Order order)? success, TResult? Function(String message)? error, }) => @@ -637,6 +1377,9 @@ mixin _$OrderFormState { TResult maybeWhen({ TResult Function()? initial, TResult Function()? loading, + TResult Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult Function(Order order)? success, TResult Function(String message)? error, required TResult orElse(), @@ -646,6 +1389,7 @@ mixin _$OrderFormState { TResult map({ required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, required TResult Function(_Success value) success, required TResult Function(_Error value) error, }) => @@ -654,6 +1398,7 @@ mixin _$OrderFormState { TResult? mapOrNull({ TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, TResult? Function(_Success value)? success, TResult? Function(_Error value)? error, }) => @@ -662,6 +1407,7 @@ mixin _$OrderFormState { TResult maybeMap({ TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, TResult Function(_Success value)? success, TResult Function(_Error value)? error, required TResult orElse(), @@ -733,6 +1479,9 @@ class _$InitialImpl implements _Initial { TResult when({ required TResult Function() initial, required TResult Function() loading, + required TResult Function( + Order order, List selectedItems, bool isAllSelected) + loaded, required TResult Function(Order order) success, required TResult Function(String message) error, }) { @@ -744,6 +1493,9 @@ class _$InitialImpl implements _Initial { TResult? whenOrNull({ TResult? Function()? initial, TResult? Function()? loading, + TResult? Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult? Function(Order order)? success, TResult? Function(String message)? error, }) { @@ -755,6 +1507,9 @@ class _$InitialImpl implements _Initial { TResult maybeWhen({ TResult Function()? initial, TResult Function()? loading, + TResult Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult Function(Order order)? success, TResult Function(String message)? error, required TResult orElse(), @@ -770,6 +1525,7 @@ class _$InitialImpl implements _Initial { TResult map({ required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, required TResult Function(_Success value) success, required TResult Function(_Error value) error, }) { @@ -781,6 +1537,7 @@ class _$InitialImpl implements _Initial { TResult? mapOrNull({ TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, TResult? Function(_Success value)? success, TResult? Function(_Error value)? error, }) { @@ -792,6 +1549,7 @@ class _$InitialImpl implements _Initial { TResult maybeMap({ TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, TResult Function(_Success value)? success, TResult Function(_Error value)? error, required TResult orElse(), @@ -850,6 +1608,9 @@ class _$LoadingImpl implements _Loading { TResult when({ required TResult Function() initial, required TResult Function() loading, + required TResult Function( + Order order, List selectedItems, bool isAllSelected) + loaded, required TResult Function(Order order) success, required TResult Function(String message) error, }) { @@ -861,6 +1622,9 @@ class _$LoadingImpl implements _Loading { TResult? whenOrNull({ TResult? Function()? initial, TResult? Function()? loading, + TResult? Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult? Function(Order order)? success, TResult? Function(String message)? error, }) { @@ -872,6 +1636,9 @@ class _$LoadingImpl implements _Loading { TResult maybeWhen({ TResult Function()? initial, TResult Function()? loading, + TResult Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult Function(Order order)? success, TResult Function(String message)? error, required TResult orElse(), @@ -887,6 +1654,7 @@ class _$LoadingImpl implements _Loading { TResult map({ required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, required TResult Function(_Success value) success, required TResult Function(_Error value) error, }) { @@ -898,6 +1666,7 @@ class _$LoadingImpl implements _Loading { TResult? mapOrNull({ TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, TResult? Function(_Success value)? success, TResult? Function(_Error value)? error, }) { @@ -909,6 +1678,7 @@ class _$LoadingImpl implements _Loading { TResult maybeMap({ TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, TResult Function(_Success value)? success, TResult Function(_Error value)? error, required TResult orElse(), @@ -924,6 +1694,206 @@ abstract class _Loading implements OrderFormState { const factory _Loading() = _$LoadingImpl; } +/// @nodoc +abstract class _$$LoadedImplCopyWith<$Res> { + factory _$$LoadedImplCopyWith( + _$LoadedImpl value, $Res Function(_$LoadedImpl) then) = + __$$LoadedImplCopyWithImpl<$Res>; + @useResult + $Res call({Order order, List selectedItems, bool isAllSelected}); +} + +/// @nodoc +class __$$LoadedImplCopyWithImpl<$Res> + extends _$OrderFormStateCopyWithImpl<$Res, _$LoadedImpl> + implements _$$LoadedImplCopyWith<$Res> { + __$$LoadedImplCopyWithImpl( + _$LoadedImpl _value, $Res Function(_$LoadedImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderFormState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? order = null, + Object? selectedItems = null, + Object? isAllSelected = null, + }) { + return _then(_$LoadedImpl( + order: null == order + ? _value.order + : order // ignore: cast_nullable_to_non_nullable + as Order, + selectedItems: null == selectedItems + ? _value._selectedItems + : selectedItems // ignore: cast_nullable_to_non_nullable + as List, + isAllSelected: null == isAllSelected + ? _value.isAllSelected + : isAllSelected // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$LoadedImpl implements _Loaded { + const _$LoadedImpl( + {required this.order, + final List selectedItems = const [], + this.isAllSelected = false}) + : _selectedItems = selectedItems; + + @override + final Order order; + final List _selectedItems; + @override + @JsonKey() + List get selectedItems { + if (_selectedItems is EqualUnmodifiableListView) return _selectedItems; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_selectedItems); + } + + @override + @JsonKey() + final bool isAllSelected; + + @override + String toString() { + return 'OrderFormState.loaded(order: $order, selectedItems: $selectedItems, isAllSelected: $isAllSelected)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LoadedImpl && + (identical(other.order, order) || other.order == order) && + const DeepCollectionEquality() + .equals(other._selectedItems, _selectedItems) && + (identical(other.isAllSelected, isAllSelected) || + other.isAllSelected == isAllSelected)); + } + + @override + int get hashCode => Object.hash(runtimeType, order, + const DeepCollectionEquality().hash(_selectedItems), isAllSelected); + + /// Create a copy of OrderFormState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => + __$$LoadedImplCopyWithImpl<_$LoadedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function( + Order order, List selectedItems, bool isAllSelected) + loaded, + required TResult Function(Order order) success, + required TResult Function(String message) error, + }) { + return loaded(order, selectedItems, isAllSelected); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, + TResult? Function(Order order)? success, + TResult? Function(String message)? error, + }) { + return loaded?.call(order, selectedItems, isAllSelected); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, + TResult Function(Order order)? success, + TResult Function(String message)? error, + required TResult orElse(), + }) { + if (loaded != null) { + return loaded(order, selectedItems, isAllSelected); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, + required TResult Function(_Success value) success, + required TResult Function(_Error value) error, + }) { + return loaded(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, + TResult? Function(_Success value)? success, + TResult? Function(_Error value)? error, + }) { + return loaded?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, + TResult Function(_Success value)? success, + TResult Function(_Error value)? error, + required TResult orElse(), + }) { + if (loaded != null) { + return loaded(this); + } + return orElse(); + } +} + +abstract class _Loaded implements OrderFormState { + const factory _Loaded( + {required final Order order, + final List selectedItems, + final bool isAllSelected}) = _$LoadedImpl; + + Order get order; + List get selectedItems; + bool get isAllSelected; + + /// Create a copy of OrderFormState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => + throw _privateConstructorUsedError; +} + /// @nodoc abstract class _$$SuccessImplCopyWith<$Res> { factory _$$SuccessImplCopyWith( @@ -994,6 +1964,9 @@ class _$SuccessImpl implements _Success { TResult when({ required TResult Function() initial, required TResult Function() loading, + required TResult Function( + Order order, List selectedItems, bool isAllSelected) + loaded, required TResult Function(Order order) success, required TResult Function(String message) error, }) { @@ -1005,6 +1978,9 @@ class _$SuccessImpl implements _Success { TResult? whenOrNull({ TResult? Function()? initial, TResult? Function()? loading, + TResult? Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult? Function(Order order)? success, TResult? Function(String message)? error, }) { @@ -1016,6 +1992,9 @@ class _$SuccessImpl implements _Success { TResult maybeWhen({ TResult Function()? initial, TResult Function()? loading, + TResult Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult Function(Order order)? success, TResult Function(String message)? error, required TResult orElse(), @@ -1031,6 +2010,7 @@ class _$SuccessImpl implements _Success { TResult map({ required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, required TResult Function(_Success value) success, required TResult Function(_Error value) error, }) { @@ -1042,6 +2022,7 @@ class _$SuccessImpl implements _Success { TResult? mapOrNull({ TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, TResult? Function(_Success value)? success, TResult? Function(_Error value)? error, }) { @@ -1053,6 +2034,7 @@ class _$SuccessImpl implements _Success { TResult maybeMap({ TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, TResult Function(_Success value)? success, TResult Function(_Error value)? error, required TResult orElse(), @@ -1146,6 +2128,9 @@ class _$ErrorImpl implements _Error { TResult when({ required TResult Function() initial, required TResult Function() loading, + required TResult Function( + Order order, List selectedItems, bool isAllSelected) + loaded, required TResult Function(Order order) success, required TResult Function(String message) error, }) { @@ -1157,6 +2142,9 @@ class _$ErrorImpl implements _Error { TResult? whenOrNull({ TResult? Function()? initial, TResult? Function()? loading, + TResult? Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult? Function(Order order)? success, TResult? Function(String message)? error, }) { @@ -1168,6 +2156,9 @@ class _$ErrorImpl implements _Error { TResult maybeWhen({ TResult Function()? initial, TResult Function()? loading, + TResult Function( + Order order, List selectedItems, bool isAllSelected)? + loaded, TResult Function(Order order)? success, TResult Function(String message)? error, required TResult orElse(), @@ -1183,6 +2174,7 @@ class _$ErrorImpl implements _Error { TResult map({ required TResult Function(_Initial value) initial, required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, required TResult Function(_Success value) success, required TResult Function(_Error value) error, }) { @@ -1194,6 +2186,7 @@ class _$ErrorImpl implements _Error { TResult? mapOrNull({ TResult? Function(_Initial value)? initial, TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, TResult? Function(_Success value)? success, TResult? Function(_Error value)? error, }) { @@ -1205,6 +2198,7 @@ class _$ErrorImpl implements _Error { TResult maybeMap({ TResult Function(_Initial value)? initial, TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, TResult Function(_Success value)? success, TResult Function(_Error value)? error, required TResult orElse(), diff --git a/lib/presentation/home/bloc/order_form/order_form_event.dart b/lib/presentation/home/bloc/order_form/order_form_event.dart index d6f0731..d557ce1 100644 --- a/lib/presentation/home/bloc/order_form/order_form_event.dart +++ b/lib/presentation/home/bloc/order_form/order_form_event.dart @@ -2,6 +2,7 @@ part of 'order_form_bloc.dart'; @freezed class OrderFormEvent with _$OrderFormEvent { + const factory OrderFormEvent.started(Order order) = _Started; const factory OrderFormEvent.create({ required List items, required String customerName, @@ -15,4 +16,8 @@ class OrderFormEvent with _$OrderFormEvent { required String tableNumber, required PaymentMethod paymentMethod, }) = _CreateWithPaymentMethod; + const factory OrderFormEvent.toggleItem(OrderItem item) = _ToggleItem; + const factory OrderFormEvent.toggleSelectAll(bool selectAll) = + _ToggleSelectAll; + const factory OrderFormEvent.refund() = _Refund; } diff --git a/lib/presentation/home/bloc/order_form/order_form_state.dart b/lib/presentation/home/bloc/order_form/order_form_state.dart index 9b78733..65c6111 100644 --- a/lib/presentation/home/bloc/order_form/order_form_state.dart +++ b/lib/presentation/home/bloc/order_form/order_form_state.dart @@ -4,6 +4,11 @@ part of 'order_form_bloc.dart'; class OrderFormState with _$OrderFormState { const factory OrderFormState.initial() = _Initial; const factory OrderFormState.loading() = _Loading; + const factory OrderFormState.loaded({ + required Order order, + @Default([]) List selectedItems, + @Default(false) bool isAllSelected, + }) = _Loaded; const factory OrderFormState.success(Order order) = _Success; const factory OrderFormState.error(String message) = _Error; } diff --git a/lib/presentation/home/pages/home_page.dart b/lib/presentation/home/pages/home_page.dart index 8da5814..e27f67b 100644 --- a/lib/presentation/home/pages/home_page.dart +++ b/lib/presentation/home/pages/home_page.dart @@ -532,7 +532,8 @@ class _HomePageState extends State { elevation: 1, disabled: items.isEmpty, onPressed: () { - if (orderType.name == 'dineIn') { + if (orderType.name == 'dineIn' && + widget.table == null) { AppFlushbar.showError(context, 'Mohon pilih meja terlebih dahulu'); return; @@ -544,7 +545,7 @@ class _HomePageState extends State { table: widget.table, )); }, - label: 'Lanjutkan Pembayaran ', + label: 'Lanjutkan Pembayaran', ), ), ), diff --git a/lib/presentation/sales/pages/sales_page.dart b/lib/presentation/sales/pages/sales_page.dart index 610745e..38baeb4 100644 --- a/lib/presentation/sales/pages/sales_page.dart +++ b/lib/presentation/sales/pages/sales_page.dart @@ -1,6 +1,7 @@ import 'package:enaklo_pos/core/components/buttons.dart'; import 'package:enaklo_pos/core/components/spaces.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart'; +import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart'; import 'package:enaklo_pos/presentation/sales/blocs/day_sales/day_sales_bloc.dart'; import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart'; import 'package:enaklo_pos/presentation/sales/dialog/payment_dialog.dart'; @@ -127,6 +128,9 @@ class _SalesPageState extends State { setState(() { orderDetail = filtered[index]; }); + context.read().add( + OrderFormEvent.started( + filtered[index])); }, child: SalesCard( order: orders[index], diff --git a/lib/presentation/sales/widgets/sales_list_order.dart b/lib/presentation/sales/widgets/sales_list_order.dart index 1fa83ec..15d5a2b 100644 --- a/lib/presentation/sales/widgets/sales_list_order.dart +++ b/lib/presentation/sales/widgets/sales_list_order.dart @@ -1,8 +1,11 @@ import 'package:enaklo_pos/core/components/spaces.dart'; import 'package:enaklo_pos/core/constants/colors.dart'; +import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; import 'package:enaklo_pos/core/extensions/string_ext.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart'; +import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; class SalesListOrder extends StatelessWidget { final Order? order; @@ -16,62 +19,106 @@ class SalesListOrder extends StatelessWidget { color: AppColors.white, borderRadius: BorderRadius.circular(8), ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - padding: const EdgeInsets.all(16), - width: double.infinity, - decoration: const BoxDecoration( - border: Border( - bottom: BorderSide(color: AppColors.background), - ), + child: BlocBuilder( + builder: (context, state) { + return state.maybeWhen( + orElse: () => const SizedBox.shrink(), + loaded: (orderX, selectedItems, isAllSelected) => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: const EdgeInsets.all(16), + width: double.infinity, + decoration: const BoxDecoration( + border: Border( + bottom: BorderSide(color: AppColors.background), + ), + ), + child: Row( + children: [ + Checkbox( + value: isAllSelected, + activeColor: AppColors.primary, + onChanged: (val) { + context.read().add( + OrderFormEvent.toggleSelectAll(val ?? false)); + }, + ), + Text( + 'Daftar Pembelian', + style: TextStyle( + color: AppColors.black, + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ), + ), + SpaceHeight(12), + Column( + children: List.generate( + order?.orderItems?.length ?? 0, + (index) { + final item = order!.orderItems![index]; + final isSelected = + selectedItems.any((e) => e.id == item.id); + return _item( + context, + isSelected, + item, + ); + }, + ).toList(), + ), + ], ), - child: Text( - 'Daftar Pembelian', - style: TextStyle( - color: AppColors.black, - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - ), - SpaceHeight(12), - Column( - children: List.generate( - order?.orderItems?.length ?? 0, - (index) => _item(order!.orderItems![index]), - ).toList(), - ), - ], + ); + }, ), ); } - Padding _item(OrderItem product) { + Padding _item(BuildContext context, bool isSelected, OrderItem product) { return Padding( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16) .copyWith(top: 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - product.productName ?? '', - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.w600, + SizedBox( + width: context.deviceWidth * 0.2, + child: Row( + children: [ + Checkbox( + value: isSelected, + activeColor: AppColors.primary, + onChanged: (_) { + context + .read() + .add(OrderFormEvent.toggleItem(product)); + }, ), - ), - Text( - (product.unitPrice ?? 0).toString().currencyFormatRpV2, - style: const TextStyle( - fontSize: 14, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + product.productName ?? '', + style: const TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + Text( + (product.unitPrice ?? 0).toString().currencyFormatRpV2, + style: const TextStyle( + fontSize: 14, + ), + ), + ], ), - ), - ], + ], + ), ), Text( 'X${product.quantity}',