transfer table

This commit is contained in:
efrilm
2025-10-26 19:36:59 +07:00
parent d5ed3f62ff
commit 5c683eda8d
15 changed files with 736 additions and 54 deletions
@@ -65,6 +65,32 @@ class TableFormBloc extends Bloc<TableFormEvent, TableFormState> {
),
);
},
transfer: (e) async {
Either<TableFailure, Unit> failureOrTableTransfer;
emit(
state.copyWith(isTransfering: true, failureOrTableTransfer: none()),
);
final isFromTableIdValid = e.fromTableId.isNotEmpty;
final isToTableIdValid = e.toTableId.isNotEmpty;
if (isFromTableIdValid && isToTableIdValid) {
failureOrTableTransfer = await _repository.transferTable(
fromTableId: e.fromTableId,
toTableId: e.toTableId,
);
emit(
state.copyWith(
failureOrTableTransfer: optionOf(failureOrTableTransfer),
isTransfering: false,
),
);
}
emit(state.copyWith(failureOrTable: none(), isCreating: false));
},
);
}
}
@@ -23,6 +23,7 @@ mixin _$TableFormEvent {
required TResult Function(String capacity) capacityChanged,
required TResult Function() created,
required TResult Function(String id, Offset position) updated,
required TResult Function(String fromTableId, String toTableId) transfer,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
@@ -30,6 +31,7 @@ mixin _$TableFormEvent {
TResult? Function(String capacity)? capacityChanged,
TResult? Function()? created,
TResult? Function(String id, Offset position)? updated,
TResult? Function(String fromTableId, String toTableId)? transfer,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
@@ -37,6 +39,7 @@ mixin _$TableFormEvent {
TResult Function(String capacity)? capacityChanged,
TResult Function()? created,
TResult Function(String id, Offset position)? updated,
TResult Function(String fromTableId, String toTableId)? transfer,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -45,6 +48,7 @@ mixin _$TableFormEvent {
required TResult Function(_CapacityChanged value) capacityChanged,
required TResult Function(_Created value) created,
required TResult Function(_Updated value) updated,
required TResult Function(_Transfer value) transfer,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
@@ -52,6 +56,7 @@ mixin _$TableFormEvent {
TResult? Function(_CapacityChanged value)? capacityChanged,
TResult? Function(_Created value)? created,
TResult? Function(_Updated value)? updated,
TResult? Function(_Transfer value)? transfer,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
@@ -59,6 +64,7 @@ mixin _$TableFormEvent {
TResult Function(_CapacityChanged value)? capacityChanged,
TResult Function(_Created value)? created,
TResult Function(_Updated value)? updated,
TResult Function(_Transfer value)? transfer,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
@@ -159,6 +165,7 @@ class _$NameChangedImpl implements _NameChanged {
required TResult Function(String capacity) capacityChanged,
required TResult Function() created,
required TResult Function(String id, Offset position) updated,
required TResult Function(String fromTableId, String toTableId) transfer,
}) {
return nameChanged(name);
}
@@ -170,6 +177,7 @@ class _$NameChangedImpl implements _NameChanged {
TResult? Function(String capacity)? capacityChanged,
TResult? Function()? created,
TResult? Function(String id, Offset position)? updated,
TResult? Function(String fromTableId, String toTableId)? transfer,
}) {
return nameChanged?.call(name);
}
@@ -181,6 +189,7 @@ class _$NameChangedImpl implements _NameChanged {
TResult Function(String capacity)? capacityChanged,
TResult Function()? created,
TResult Function(String id, Offset position)? updated,
TResult Function(String fromTableId, String toTableId)? transfer,
required TResult orElse(),
}) {
if (nameChanged != null) {
@@ -196,6 +205,7 @@ class _$NameChangedImpl implements _NameChanged {
required TResult Function(_CapacityChanged value) capacityChanged,
required TResult Function(_Created value) created,
required TResult Function(_Updated value) updated,
required TResult Function(_Transfer value) transfer,
}) {
return nameChanged(this);
}
@@ -207,6 +217,7 @@ class _$NameChangedImpl implements _NameChanged {
TResult? Function(_CapacityChanged value)? capacityChanged,
TResult? Function(_Created value)? created,
TResult? Function(_Updated value)? updated,
TResult? Function(_Transfer value)? transfer,
}) {
return nameChanged?.call(this);
}
@@ -218,6 +229,7 @@ class _$NameChangedImpl implements _NameChanged {
TResult Function(_CapacityChanged value)? capacityChanged,
TResult Function(_Created value)? created,
TResult Function(_Updated value)? updated,
TResult Function(_Transfer value)? transfer,
required TResult orElse(),
}) {
if (nameChanged != null) {
@@ -317,6 +329,7 @@ class _$CapacityChangedImpl implements _CapacityChanged {
required TResult Function(String capacity) capacityChanged,
required TResult Function() created,
required TResult Function(String id, Offset position) updated,
required TResult Function(String fromTableId, String toTableId) transfer,
}) {
return capacityChanged(capacity);
}
@@ -328,6 +341,7 @@ class _$CapacityChangedImpl implements _CapacityChanged {
TResult? Function(String capacity)? capacityChanged,
TResult? Function()? created,
TResult? Function(String id, Offset position)? updated,
TResult? Function(String fromTableId, String toTableId)? transfer,
}) {
return capacityChanged?.call(capacity);
}
@@ -339,6 +353,7 @@ class _$CapacityChangedImpl implements _CapacityChanged {
TResult Function(String capacity)? capacityChanged,
TResult Function()? created,
TResult Function(String id, Offset position)? updated,
TResult Function(String fromTableId, String toTableId)? transfer,
required TResult orElse(),
}) {
if (capacityChanged != null) {
@@ -354,6 +369,7 @@ class _$CapacityChangedImpl implements _CapacityChanged {
required TResult Function(_CapacityChanged value) capacityChanged,
required TResult Function(_Created value) created,
required TResult Function(_Updated value) updated,
required TResult Function(_Transfer value) transfer,
}) {
return capacityChanged(this);
}
@@ -365,6 +381,7 @@ class _$CapacityChangedImpl implements _CapacityChanged {
TResult? Function(_CapacityChanged value)? capacityChanged,
TResult? Function(_Created value)? created,
TResult? Function(_Updated value)? updated,
TResult? Function(_Transfer value)? transfer,
}) {
return capacityChanged?.call(this);
}
@@ -376,6 +393,7 @@ class _$CapacityChangedImpl implements _CapacityChanged {
TResult Function(_CapacityChanged value)? capacityChanged,
TResult Function(_Created value)? created,
TResult Function(_Updated value)? updated,
TResult Function(_Transfer value)? transfer,
required TResult orElse(),
}) {
if (capacityChanged != null) {
@@ -444,6 +462,7 @@ class _$CreatedImpl implements _Created {
required TResult Function(String capacity) capacityChanged,
required TResult Function() created,
required TResult Function(String id, Offset position) updated,
required TResult Function(String fromTableId, String toTableId) transfer,
}) {
return created();
}
@@ -455,6 +474,7 @@ class _$CreatedImpl implements _Created {
TResult? Function(String capacity)? capacityChanged,
TResult? Function()? created,
TResult? Function(String id, Offset position)? updated,
TResult? Function(String fromTableId, String toTableId)? transfer,
}) {
return created?.call();
}
@@ -466,6 +486,7 @@ class _$CreatedImpl implements _Created {
TResult Function(String capacity)? capacityChanged,
TResult Function()? created,
TResult Function(String id, Offset position)? updated,
TResult Function(String fromTableId, String toTableId)? transfer,
required TResult orElse(),
}) {
if (created != null) {
@@ -481,6 +502,7 @@ class _$CreatedImpl implements _Created {
required TResult Function(_CapacityChanged value) capacityChanged,
required TResult Function(_Created value) created,
required TResult Function(_Updated value) updated,
required TResult Function(_Transfer value) transfer,
}) {
return created(this);
}
@@ -492,6 +514,7 @@ class _$CreatedImpl implements _Created {
TResult? Function(_CapacityChanged value)? capacityChanged,
TResult? Function(_Created value)? created,
TResult? Function(_Updated value)? updated,
TResult? Function(_Transfer value)? transfer,
}) {
return created?.call(this);
}
@@ -503,6 +526,7 @@ class _$CreatedImpl implements _Created {
TResult Function(_CapacityChanged value)? capacityChanged,
TResult Function(_Created value)? created,
TResult Function(_Updated value)? updated,
TResult Function(_Transfer value)? transfer,
required TResult orElse(),
}) {
if (created != null) {
@@ -598,6 +622,7 @@ class _$UpdatedImpl implements _Updated {
required TResult Function(String capacity) capacityChanged,
required TResult Function() created,
required TResult Function(String id, Offset position) updated,
required TResult Function(String fromTableId, String toTableId) transfer,
}) {
return updated(id, position);
}
@@ -609,6 +634,7 @@ class _$UpdatedImpl implements _Updated {
TResult? Function(String capacity)? capacityChanged,
TResult? Function()? created,
TResult? Function(String id, Offset position)? updated,
TResult? Function(String fromTableId, String toTableId)? transfer,
}) {
return updated?.call(id, position);
}
@@ -620,6 +646,7 @@ class _$UpdatedImpl implements _Updated {
TResult Function(String capacity)? capacityChanged,
TResult Function()? created,
TResult Function(String id, Offset position)? updated,
TResult Function(String fromTableId, String toTableId)? transfer,
required TResult orElse(),
}) {
if (updated != null) {
@@ -635,6 +662,7 @@ class _$UpdatedImpl implements _Updated {
required TResult Function(_CapacityChanged value) capacityChanged,
required TResult Function(_Created value) created,
required TResult Function(_Updated value) updated,
required TResult Function(_Transfer value) transfer,
}) {
return updated(this);
}
@@ -646,6 +674,7 @@ class _$UpdatedImpl implements _Updated {
TResult? Function(_CapacityChanged value)? capacityChanged,
TResult? Function(_Created value)? created,
TResult? Function(_Updated value)? updated,
TResult? Function(_Transfer value)? transfer,
}) {
return updated?.call(this);
}
@@ -657,6 +686,7 @@ class _$UpdatedImpl implements _Updated {
TResult Function(_CapacityChanged value)? capacityChanged,
TResult Function(_Created value)? created,
TResult Function(_Updated value)? updated,
TResult Function(_Transfer value)? transfer,
required TResult orElse(),
}) {
if (updated != null) {
@@ -682,14 +712,190 @@ abstract class _Updated implements TableFormEvent {
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$TransferImplCopyWith<$Res> {
factory _$$TransferImplCopyWith(
_$TransferImpl value,
$Res Function(_$TransferImpl) then,
) = __$$TransferImplCopyWithImpl<$Res>;
@useResult
$Res call({String fromTableId, String toTableId});
}
/// @nodoc
class __$$TransferImplCopyWithImpl<$Res>
extends _$TableFormEventCopyWithImpl<$Res, _$TransferImpl>
implements _$$TransferImplCopyWith<$Res> {
__$$TransferImplCopyWithImpl(
_$TransferImpl _value,
$Res Function(_$TransferImpl) _then,
) : super(_value, _then);
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? fromTableId = null, Object? toTableId = null}) {
return _then(
_$TransferImpl(
fromTableId: null == fromTableId
? _value.fromTableId
: fromTableId // ignore: cast_nullable_to_non_nullable
as String,
toTableId: null == toTableId
? _value.toTableId
: toTableId // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$TransferImpl implements _Transfer {
const _$TransferImpl({required this.fromTableId, required this.toTableId});
@override
final String fromTableId;
@override
final String toTableId;
@override
String toString() {
return 'TableFormEvent.transfer(fromTableId: $fromTableId, toTableId: $toTableId)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TransferImpl &&
(identical(other.fromTableId, fromTableId) ||
other.fromTableId == fromTableId) &&
(identical(other.toTableId, toTableId) ||
other.toTableId == toTableId));
}
@override
int get hashCode => Object.hash(runtimeType, fromTableId, toTableId);
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$TransferImplCopyWith<_$TransferImpl> get copyWith =>
__$$TransferImplCopyWithImpl<_$TransferImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String name) nameChanged,
required TResult Function(String capacity) capacityChanged,
required TResult Function() created,
required TResult Function(String id, Offset position) updated,
required TResult Function(String fromTableId, String toTableId) transfer,
}) {
return transfer(fromTableId, toTableId);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name)? nameChanged,
TResult? Function(String capacity)? capacityChanged,
TResult? Function()? created,
TResult? Function(String id, Offset position)? updated,
TResult? Function(String fromTableId, String toTableId)? transfer,
}) {
return transfer?.call(fromTableId, toTableId);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name)? nameChanged,
TResult Function(String capacity)? capacityChanged,
TResult Function()? created,
TResult Function(String id, Offset position)? updated,
TResult Function(String fromTableId, String toTableId)? transfer,
required TResult orElse(),
}) {
if (transfer != null) {
return transfer(fromTableId, toTableId);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_NameChanged value) nameChanged,
required TResult Function(_CapacityChanged value) capacityChanged,
required TResult Function(_Created value) created,
required TResult Function(_Updated value) updated,
required TResult Function(_Transfer value) transfer,
}) {
return transfer(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_NameChanged value)? nameChanged,
TResult? Function(_CapacityChanged value)? capacityChanged,
TResult? Function(_Created value)? created,
TResult? Function(_Updated value)? updated,
TResult? Function(_Transfer value)? transfer,
}) {
return transfer?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_NameChanged value)? nameChanged,
TResult Function(_CapacityChanged value)? capacityChanged,
TResult Function(_Created value)? created,
TResult Function(_Updated value)? updated,
TResult Function(_Transfer value)? transfer,
required TResult orElse(),
}) {
if (transfer != null) {
return transfer(this);
}
return orElse();
}
}
abstract class _Transfer implements TableFormEvent {
const factory _Transfer({
required final String fromTableId,
required final String toTableId,
}) = _$TransferImpl;
String get fromTableId;
String get toTableId;
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$TransferImplCopyWith<_$TransferImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$TableFormState {
String get name => throw _privateConstructorUsedError;
int get capacity => throw _privateConstructorUsedError;
Option<Either<TableFailure, Table>> get failureOrTable =>
throw _privateConstructorUsedError;
Option<Either<TableFailure, Unit>> get failureOrTableTransfer =>
throw _privateConstructorUsedError;
bool get isUpdating => throw _privateConstructorUsedError;
bool get isCreating => throw _privateConstructorUsedError;
bool get isTransfering => throw _privateConstructorUsedError;
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@@ -709,8 +915,10 @@ abstract class $TableFormStateCopyWith<$Res> {
String name,
int capacity,
Option<Either<TableFailure, Table>> failureOrTable,
Option<Either<TableFailure, Unit>> failureOrTableTransfer,
bool isUpdating,
bool isCreating,
bool isTransfering,
});
}
@@ -732,8 +940,10 @@ class _$TableFormStateCopyWithImpl<$Res, $Val extends TableFormState>
Object? name = null,
Object? capacity = null,
Object? failureOrTable = null,
Object? failureOrTableTransfer = null,
Object? isUpdating = null,
Object? isCreating = null,
Object? isTransfering = null,
}) {
return _then(
_value.copyWith(
@@ -749,6 +959,10 @@ class _$TableFormStateCopyWithImpl<$Res, $Val extends TableFormState>
? _value.failureOrTable
: failureOrTable // ignore: cast_nullable_to_non_nullable
as Option<Either<TableFailure, Table>>,
failureOrTableTransfer: null == failureOrTableTransfer
? _value.failureOrTableTransfer
: failureOrTableTransfer // ignore: cast_nullable_to_non_nullable
as Option<Either<TableFailure, Unit>>,
isUpdating: null == isUpdating
? _value.isUpdating
: isUpdating // ignore: cast_nullable_to_non_nullable
@@ -757,6 +971,10 @@ class _$TableFormStateCopyWithImpl<$Res, $Val extends TableFormState>
? _value.isCreating
: isCreating // ignore: cast_nullable_to_non_nullable
as bool,
isTransfering: null == isTransfering
? _value.isTransfering
: isTransfering // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
@@ -776,8 +994,10 @@ abstract class _$$TableFormStateImplCopyWith<$Res>
String name,
int capacity,
Option<Either<TableFailure, Table>> failureOrTable,
Option<Either<TableFailure, Unit>> failureOrTableTransfer,
bool isUpdating,
bool isCreating,
bool isTransfering,
});
}
@@ -798,8 +1018,10 @@ class __$$TableFormStateImplCopyWithImpl<$Res>
Object? name = null,
Object? capacity = null,
Object? failureOrTable = null,
Object? failureOrTableTransfer = null,
Object? isUpdating = null,
Object? isCreating = null,
Object? isTransfering = null,
}) {
return _then(
_$TableFormStateImpl(
@@ -815,6 +1037,10 @@ class __$$TableFormStateImplCopyWithImpl<$Res>
? _value.failureOrTable
: failureOrTable // ignore: cast_nullable_to_non_nullable
as Option<Either<TableFailure, Table>>,
failureOrTableTransfer: null == failureOrTableTransfer
? _value.failureOrTableTransfer
: failureOrTableTransfer // ignore: cast_nullable_to_non_nullable
as Option<Either<TableFailure, Unit>>,
isUpdating: null == isUpdating
? _value.isUpdating
: isUpdating // ignore: cast_nullable_to_non_nullable
@@ -823,6 +1049,10 @@ class __$$TableFormStateImplCopyWithImpl<$Res>
? _value.isCreating
: isCreating // ignore: cast_nullable_to_non_nullable
as bool,
isTransfering: null == isTransfering
? _value.isTransfering
: isTransfering // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
@@ -835,8 +1065,10 @@ class _$TableFormStateImpl implements _TableFormState {
required this.name,
required this.capacity,
required this.failureOrTable,
required this.failureOrTableTransfer,
this.isUpdating = false,
this.isCreating = false,
this.isTransfering = false,
});
@override
@@ -846,15 +1078,20 @@ class _$TableFormStateImpl implements _TableFormState {
@override
final Option<Either<TableFailure, Table>> failureOrTable;
@override
final Option<Either<TableFailure, Unit>> failureOrTableTransfer;
@override
@JsonKey()
final bool isUpdating;
@override
@JsonKey()
final bool isCreating;
@override
@JsonKey()
final bool isTransfering;
@override
String toString() {
return 'TableFormState(name: $name, capacity: $capacity, failureOrTable: $failureOrTable, isUpdating: $isUpdating, isCreating: $isCreating)';
return 'TableFormState(name: $name, capacity: $capacity, failureOrTable: $failureOrTable, failureOrTableTransfer: $failureOrTableTransfer, isUpdating: $isUpdating, isCreating: $isCreating, isTransfering: $isTransfering)';
}
@override
@@ -867,10 +1104,14 @@ class _$TableFormStateImpl implements _TableFormState {
other.capacity == capacity) &&
(identical(other.failureOrTable, failureOrTable) ||
other.failureOrTable == failureOrTable) &&
(identical(other.failureOrTableTransfer, failureOrTableTransfer) ||
other.failureOrTableTransfer == failureOrTableTransfer) &&
(identical(other.isUpdating, isUpdating) ||
other.isUpdating == isUpdating) &&
(identical(other.isCreating, isCreating) ||
other.isCreating == isCreating));
other.isCreating == isCreating) &&
(identical(other.isTransfering, isTransfering) ||
other.isTransfering == isTransfering));
}
@override
@@ -879,8 +1120,10 @@ class _$TableFormStateImpl implements _TableFormState {
name,
capacity,
failureOrTable,
failureOrTableTransfer,
isUpdating,
isCreating,
isTransfering,
);
/// Create a copy of TableFormState
@@ -900,8 +1143,10 @@ abstract class _TableFormState implements TableFormState {
required final String name,
required final int capacity,
required final Option<Either<TableFailure, Table>> failureOrTable,
required final Option<Either<TableFailure, Unit>> failureOrTableTransfer,
final bool isUpdating,
final bool isCreating,
final bool isTransfering,
}) = _$TableFormStateImpl;
@override
@@ -911,9 +1156,13 @@ abstract class _TableFormState implements TableFormState {
@override
Option<Either<TableFailure, Table>> get failureOrTable;
@override
Option<Either<TableFailure, Unit>> get failureOrTableTransfer;
@override
bool get isUpdating;
@override
bool get isCreating;
@override
bool get isTransfering;
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@@ -10,4 +10,8 @@ class TableFormEvent with _$TableFormEvent {
required String id,
required Offset position,
}) = _Updated;
const factory TableFormEvent.transfer({
required String fromTableId,
required String toTableId,
}) = _Transfer;
}
@@ -6,10 +6,16 @@ class TableFormState with _$TableFormState {
required String name,
required int capacity,
required Option<Either<TableFailure, Table>> failureOrTable,
required Option<Either<TableFailure, Unit>> failureOrTableTransfer,
@Default(false) bool isUpdating,
@Default(false) bool isCreating,
@Default(false) bool isTransfering,
}) = _TableFormState;
factory TableFormState.initial() =>
TableFormState(failureOrTable: none(), name: '', capacity: 0);
factory TableFormState.initial() => TableFormState(
failureOrTable: none(),
name: '',
capacity: 0,
failureOrTableTransfer: none(),
);
}