FarmManagementBloc constructor

FarmManagementBloc()

Implementation

FarmManagementBloc() : super() {
  on<ChangeTabEvent>((event, emit) => emit(ChangeTabState(event.index)));
  on<ChangeUnitEvent>((event, emit) => emit(ChangeUnitState()));
  on<LoadListEvent>((event, emit) async {
    emit(const BaseState(isShowLoading: true));
    final resp = await ApiClient().getAPI('/api/v2/process_engineerings?page=${event.page}&limit=20&keyword=${event.keyword}', FarmManageModels(), hasHeader: true);
    emit(LoadListState(resp));
  });
  on<CreatePlanEvent>((event, emit) async {
    emit(const BaseState(isShowLoading: true));
    final String id = event.id > 0 ? '/${event.id}' : '';
    final resp = await ApiClient().postAPI('/api/v2/process_engineerings$id', event.id > 0 ? 'PUT' : 'POST', FarmManageModel(),
      hasHeader: true, body: {
        'title': event.name,
        'culture_plot_id': event.plots,
        'family_tree': event.tree,
        'start_date': event.start,
        'end_date': event.end,
        if (event.qty.isNotEmpty) 'amount': event.qty,
        'unit': event.unit,
        if (event.total.isNotEmpty) 'revenue': event.total,
        'other_unit': event.otherUnit
      });
    emit(CreatePlanState(resp));
  });
  on<DeletePlanEvent>((event, emit) async {
    emit(const BaseState(isShowLoading: true));
    final resp = await ApiClient().postAPI('/api/v2/process_engineerings/${event.id}', 'DELETE', BaseResponse(), hasHeader: true);
    emit(DeletePlanState(resp));
  });
}