AutoWeighingMachineDtls method

Future<bool> AutoWeighingMachineDtls()

Implementation

Future<bool> AutoWeighingMachineDtls() async {
  print(tblTRLoadingWeighingTO.machineIP != null);
  print(tblTRLoadingWeighingTO.weighingMachineId);
  isConfirmButtonEnabled.value = false;
  AutoWeighingTO = WeighingTO();
  tblTRLoadingWeighingTO.actualWeight = null;
  measurementController.value.clear();
  if (tblTRLoadingWeighingTO.machineIP != null &&
      tblTRLoadingWeighingTO.weighingMachineId != null) {
    isLoading(true);
    AutoWeighingTO = WeighingTO();
    WBAutoWeighingTO = WeighingTO();

    final Map<String, dynamic> params = {
      'ipAddr': tblTRLoadingWeighingTO.machineIP,
      'machineId': tblTRLoadingWeighingTO.weighingMachineId,
      'ShowWeightOrFullTIcket': 0,
    };

    try {
      final response = await _apiService
          .getData(AppUrls.getLatestWeightByMachineIp, queryParams: params);
      if (response.statusCode == 200) {
        AutoWeighingTO = WeighingTO.fromJson(response.data);
        tblTRLoadingWeighingTO.actualWeight =
            AutoWeighingTO.measurement as num;
        measurementController.value.text =
            AutoWeighingTO.measurement.toString();
        final numericValue =
            int.tryParse(measurementController.value.text.trim()) ?? 0;
        isPlayButtonEnabled.value = numericValue > 0;

        if (selectVehicleNo.value == null) {
          isConfirmButtonEnabled.value = false;
          AppUtils.showSnackBar('Please Select Vehicle');
          return false;
        }

        if (tblTRLoadingWeighingTO.actualWeight == null ||
            tblTRLoadingWeighingTO.actualWeight! <= 0) {
          isConfirmButtonEnabled.value = false;
          AppUtils.showSnackBar('Please Add Measurement');
          return false;
        }
        return true;
      } else {
        AppUtils.showSnackBar(
            'Weight not measured. Please Try One more time.');
        return false;
      }
    } catch (e) {
      print(e);
      return false;
    } finally {
      isLoading(false);
    }
  } else {
    AppUtils.showSnackBar('Machine IP Not Found');
    return false; // Add return for the else case
  }
}