Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
collections_to_schedule_bloc.dart
Go to the documentation of this file.
1import 'package:bloc/bloc.dart';
2import 'package:equatable/equatable.dart';
3
4import '../../../../../core/error/failures.dart';
5import '../../../../../core/services/service_locator.dart';
6import '../../../domain/entities/req/req_create_driver_collection_entity.dart';
7import '../../../domain/entities/res/res_collection_to_schedule_entity.dart';
8import '../../../domain/usecases/create_driver_collection_usecase.dart';
9import '../../../domain/usecases/get_collections_to_schedule_usecase.dart';
10
11part 'collections_to_schedule_event.dart';
12part 'collections_to_schedule_state.dart';
13
15 extends Bloc<CollectionsToScheduleEvent, CollectionsToScheduleState> {
18
19 CollectionsToScheduleBloc() : super(CollectionsToScheduleInitial()) {
20 on<CreateDriverCollectionEvent>(_onCreateDriverCollection);
21 on<GetCollectionsToScheduleEvent>(_onGetCollectionsToSchedule);
22 }
23
26 Emitter<CollectionsToScheduleState> emit,
27 ) async {
28 emit(CollectionsToScheduleLoading());
29
30 final result = await createDriverCollectionUseCase(event.request);
31
32 result.fold(
33 (failure) => emit(CollectionsToScheduleError(failure: failure)),
34 (success) {
35 // After successful creation, automatically fetch collections to schedule
36 add(GetCollectionsToScheduleEvent(
37 startDate: event.startDate,
38 endDate: event.endDate,
39 driverId: event.driverId,
40 ));
41 },
42 );
43 }
44
46 GetCollectionsToScheduleEvent event,
47 Emitter<CollectionsToScheduleState> emit,
48 ) async {
49 if (state is! CollectionsToScheduleLoading) {
50 emit(CollectionsToScheduleLoading());
51 }
52
53 final result = await getCollectionsToScheduleUseCase(
54 startDate: event.startDate,
55 endDate: event.endDate,
56 driverId: event.driverId,
57 );
58
59 result.fold(
60 (failure) => emit(CollectionsToScheduleError(failure: failure)),
62 );
63 }
64}
sealed class AuthenticationState extends Equatable failure
Future< void > _onGetCollectionsToSchedule(GetCollectionsToScheduleEvent event, Emitter< CollectionsToScheduleState > emit,) async
Future< void > _onCreateDriverCollection(CreateDriverCollectionEvent event, Emitter< CollectionsToScheduleState > emit,) async
sealed class CollectionsState extends Equatable collections
const CreateDriverCollectionEvent({ required this.request, required this.startDate, required this.endDate, required this.driverId, })
final String startDate
final String endDate
const CollectionsToScheduleLoaded({required this.collections})
final sl