27 lines
797 B
Dart
27 lines
797 B
Dart
|
|
import 'package:bloc/bloc.dart';
|
||
|
|
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
|
||
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||
|
|
|
||
|
|
part 'transfer_table_event.dart';
|
||
|
|
part 'transfer_table_state.dart';
|
||
|
|
part 'transfer_table_bloc.freezed.dart';
|
||
|
|
|
||
|
|
class TransferTableBloc extends Bloc<TransferTableEvent, TransferTableState> {
|
||
|
|
final TableRemoteDataSource _dataSource;
|
||
|
|
TransferTableBloc(this._dataSource) : super(TransferTableState.initial()) {
|
||
|
|
on<_TransferTable>((event, emit) async {
|
||
|
|
emit(_Loading());
|
||
|
|
|
||
|
|
final result = await _dataSource.transferTable(
|
||
|
|
fromTableId: event.fromTableId,
|
||
|
|
toTableId: event.toTableId,
|
||
|
|
);
|
||
|
|
|
||
|
|
result.fold(
|
||
|
|
(l) => emit(_Error(l)),
|
||
|
|
(r) => emit(_Success()),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|