Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
unloading_bloc.dart
Go to the documentation of this file.
1import 'package:flutter_bloc/flutter_bloc.dart';
2
3import '../../../../core/services/service_locator.dart';
4import '../../domain/usecases/get_history_unloading_usecase.dart';
5import '../../domain/usecases/get_pending_unloading_collections_usecase.dart';
6import '../../domain/usecases/get_warehouse_responsible_list_usecase.dart';
7import '../../domain/usecases/send_unloading_usecase.dart';
8import 'unloading_event.dart';
9import 'unloading_state.dart';
10
11class UnloadingBloc extends Bloc<UnloadingEvent, UnloadingState> {
16
17 UnloadingBloc() : super(UnloadingInitial()) {
18 on<GetPendingUnloadingCollectionsEvent>(_onGetPendingUnloadingCollections);
19 on<GetHistoryUnloadingEvent>(_onGetHistoryUnloading);
20 on<GetWarehouseResponsibleListEvent>(_onGetWarehouseResponsibleList);
21 on<SendUnloadingEvent>(_onSendUnloading);
22 }
23
26 Emitter<UnloadingState> emit,
27 ) async {
28 emit(UnloadingLoading());
29 final result = await getPendingUnloadingCollectionsUseCase(event.userId);
30 result.fold(
31 (failure) => emit(UnloadingError(message: failure.message)),
32 (collections) => emit(PendingUnloadingCollectionsLoaded(collections: collections)),
33 );
34 }
35
37 GetHistoryUnloadingEvent event,
38 Emitter<UnloadingState> emit,
39 ) async {
40 emit(UnloadingLoading());
41 final result = await getHistoryUnloadingUseCase(event.userId);
42 result.fold(
43 (failure) => emit(UnloadingError(message: failure.message)),
45 );
46 }
47
50 Emitter<UnloadingState> emit,
51 ) async {
52 emit(GetWarehouseResponsibleLoading());
53 final result = await getWarehouseResponsibleListUseCase(event.userId);
54 result.fold(
56 (warehouseResponsible) => emit(GetWarehouseResponsibleLoaded(
57 warehouseResponsibleList: warehouseResponsible,
58 )),
59 );
60 }
61
62 Future<void> _onSendUnloading(
63 SendUnloadingEvent event,
64 Emitter<UnloadingState> emit,
65 ) async {
66 emit(SendUnloadingLoading());
67 final result = await sendUnloadingUsecase(
69 warehouseResponsibleId: event.warehouseResponsibleId,
70 firstWeight: event.firstWeight,
71 userId: event.userId,
72 collectionVouchers: event.collectionVouchers,
73 ),
74 );
75 result.fold(
76 (failure) => emit(UnloadingError(message: failure.message)),
77 (success) => emit(SendUnloadingSuccess()),
78 );
79 }
80}
sealed class AuthenticationState extends Equatable failure
sealed class CheckInOutEvent extends Equatable userId
Future< void > _onGetHistoryUnloading(GetHistoryUnloadingEvent event, Emitter< UnloadingState > emit,) async
Future< void > _onSendUnloading(SendUnloadingEvent event, Emitter< UnloadingState > emit,) async
final GetHistoryUnloadingUseCase getHistoryUnloadingUseCase
final SendUnloadingUsecase sendUnloadingUsecase
Future< void > _onGetPendingUnloadingCollections(GetPendingUnloadingCollectionsEvent event, Emitter< UnloadingState > emit,) async
Future< void > _onGetWarehouseResponsibleList(GetWarehouseResponsibleListEvent event, Emitter< UnloadingState > emit,) async
final GetWarehouseResponsibleListUseCase getWarehouseResponsibleListUseCase
final GetPendingUnloadingCollectionsUseCase getPendingUnloadingCollectionsUseCase
sealed class CollectionsState extends Equatable collections
final String message
Definition failures.dart:0
SendUnloadingUsecase({required this.repository})
final sl
const GetPendingUnloadingCollectionsEvent({required this.userId})
const GetWarehouseResponsibleListEvent({required this.userId})
const HistoryUnloadingLoaded({required this.history})
class PendingUnloadingCollectionsLoaded extends UnloadingState history
const UnloadingError({required this.message})
const GetWarehouseResponsibleError({required this.message})