toggleGate method

Future<void> toggleGate(
  1. String eqCode
)

Implementation

Future<void> toggleGate(String eqCode) async {
  nextEqCode = '';
  vehicleImage = '';

  bool? vehicleIn;
  if (loadingTypeId == 1) {
    vehicleIn = (tblTRLoadingTO.value?.statusId ==
        LoadingStatusInternalTransferE.loading1stWeighing.value);
  } else if (loadingTypeId == 2) {
    vehicleIn = (tblTRLoadingTO.value?.statusId ==
        LoadingStatusInternalTransferE.unloading1stWeighing.value);
  }

  final Map<String, dynamic> params = {
    'Wbid': tblTRLoadingWeighingTO.weighingMachineId ?? 0,
    'IsOpen': true,
    'EqCode': eqCode,
    'VehicalIn': vehicleIn,
    'VehicleNumber': tblTRLoadingTO.value?.vehicleNo?.replaceAll(' ', ''),
    // 'VehicleNumber': 'MH03DV9030',
    'ModuleId': 23,
    'VehicleId': tblTRLoadingTO.value?.idLoading,
    'LoadingTypeId': loadingTypeId.value,
    'IsManualOpen': true,
    'UserId': GetIt.I<StorageUtils>().getUserId(),
  };

  try {
    final response =
        await _apiService.postData(AppUrls.weighingGateEvent, data: params);
    isLoading(false);
    if (response.statusCode == 200) {
      if (eqCode == 'BBO') {
        nextEqCode = 'BBI';
      } else {
        nextEqCode = 'BBO';
      }
      AppUtils.showSnackBar("Gate Opened");
    }
  } catch (error) {
    isOpenGatemanually.value = true;
    AppUtils.showSnackBar(
        'Vehicle No:-${tblTRLoadingTO.value?.vehicleNo} not found on weighing bridge ${tblTRLoadingWeighingTO.machineName}');
    showConfirmationForOpenGate();
    isLoading(false);
  }
}