postBarcodeRecognizeFromUrlOrContent method

Future<BarcodeResponseList> postBarcodeRecognizeFromUrlOrContent({
  1. String? type,
  2. String? checksumValidation,
  3. bool? detectEncoding,
  4. String? preset,
  5. int? rectX,
  6. int? rectY,
  7. int? rectWidth,
  8. int? rectHeight,
  9. bool? stripFNC,
  10. int? timeout,
  11. int? medianSmoothingWindowSize,
  12. bool? allowMedianSmoothing,
  13. bool? allowComplexBackground,
  14. bool? allowDatamatrixIndustrialBarcodes,
  15. bool? allowDecreasedImage,
  16. bool? allowDetectScanGap,
  17. bool? allowIncorrectBarcodes,
  18. bool? allowInvertImage,
  19. bool? allowMicroWhiteSpotsRemoving,
  20. bool? allowOneDFastBarcodesDetector,
  21. bool? allowOneDWipedBarsRestoration,
  22. bool? allowQRMicroQrRestoration,
  23. bool? allowRegularImage,
  24. bool? allowSaltAndPepperFiltering,
  25. bool? allowWhiteSpotsRemoving,
  26. bool? checkMore1DVariants,
  27. bool? fastScanOnly,
  28. bool? allowAdditionalRestorations,
  29. double? regionLikelihoodThresholdPercent,
  30. List<int>? scanWindowSizes,
  31. double? similarity,
  32. bool? skipDiagonalSearch,
  33. bool? readTinyBarcodes,
  34. String? australianPostEncodingTable,
  35. bool? ignoreEndingFillingPatternsForCTable,
  36. String? url,
  37. MultipartFile? image,
})

Recognize barcode from an url or from request body. Request body can contain raw data bytes of the image with content-type &quot;application/octet-stream&quot;. An image can also be passed as a form field.

Implementation

Future<BarcodeResponseList> postBarcodeRecognizeFromUrlOrContent(
    {String? type,
    String? checksumValidation,
    bool? detectEncoding,
    String? preset,
    int? rectX,
    int? rectY,
    int? rectWidth,
    int? rectHeight,
    bool? stripFNC,
    int? timeout,
    int? medianSmoothingWindowSize,
    bool? allowMedianSmoothing,
    bool? allowComplexBackground,
    bool? allowDatamatrixIndustrialBarcodes,
    bool? allowDecreasedImage,
    bool? allowDetectScanGap,
    bool? allowIncorrectBarcodes,
    bool? allowInvertImage,
    bool? allowMicroWhiteSpotsRemoving,
    bool? allowOneDFastBarcodesDetector,
    bool? allowOneDWipedBarsRestoration,
    bool? allowQRMicroQrRestoration,
    bool? allowRegularImage,
    bool? allowSaltAndPepperFiltering,
    bool? allowWhiteSpotsRemoving,
    bool? checkMore1DVariants,
    bool? fastScanOnly,
    bool? allowAdditionalRestorations,
    double? regionLikelihoodThresholdPercent,
    List<int>? scanWindowSizes,
    double? similarity,
    bool? skipDiagonalSearch,
    bool? readTinyBarcodes,
    String? australianPostEncodingTable,
    bool? ignoreEndingFillingPatternsForCTable,
    String? url,
    MultipartFile? image}) async {
  // ignore: prefer_final_locals
  Object? postBody = null;

  // create path and map variables
  final String requestPath =
      "/barcode/recognize".replaceAll("{format}", "json");

  // query params
  final List<QueryParam> queryParams = [];
  final Map<String, String> headerParams = {};
  final Map<String, String> formParams = {};
  if (type != null) {
    queryParams
        .addAll(convertParametersForCollectionFormat("", "Type", type));
  }
  if (checksumValidation != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "ChecksumValidation", checksumValidation));
  }
  if (detectEncoding != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "DetectEncoding", detectEncoding));
  }
  if (preset != null) {
    queryParams
        .addAll(convertParametersForCollectionFormat("", "Preset", preset));
  }
  if (rectX != null) {
    queryParams
        .addAll(convertParametersForCollectionFormat("", "RectX", rectX));
  }
  if (rectY != null) {
    queryParams
        .addAll(convertParametersForCollectionFormat("", "RectY", rectY));
  }
  if (rectWidth != null) {
    queryParams.addAll(
        convertParametersForCollectionFormat("", "RectWidth", rectWidth));
  }
  if (rectHeight != null) {
    queryParams.addAll(
        convertParametersForCollectionFormat("", "RectHeight", rectHeight));
  }
  if (stripFNC != null) {
    queryParams.addAll(
        convertParametersForCollectionFormat("", "StripFNC", stripFNC));
  }
  if (timeout != null) {
    queryParams
        .addAll(convertParametersForCollectionFormat("", "Timeout", timeout));
  }
  if (medianSmoothingWindowSize != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "MedianSmoothingWindowSize", medianSmoothingWindowSize));
  }
  if (allowMedianSmoothing != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowMedianSmoothing", allowMedianSmoothing));
  }
  if (allowComplexBackground != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowComplexBackground", allowComplexBackground));
  }
  if (allowDatamatrixIndustrialBarcodes != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "",
        "AllowDatamatrixIndustrialBarcodes",
        allowDatamatrixIndustrialBarcodes));
  }
  if (allowDecreasedImage != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowDecreasedImage", allowDecreasedImage));
  }
  if (allowDetectScanGap != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowDetectScanGap", allowDetectScanGap));
  }
  if (allowIncorrectBarcodes != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowIncorrectBarcodes", allowIncorrectBarcodes));
  }
  if (allowInvertImage != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowInvertImage", allowInvertImage));
  }
  if (allowMicroWhiteSpotsRemoving != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowMicroWhiteSpotsRemoving", allowMicroWhiteSpotsRemoving));
  }
  if (allowOneDFastBarcodesDetector != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowOneDFastBarcodesDetector", allowOneDFastBarcodesDetector));
  }
  if (allowOneDWipedBarsRestoration != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowOneDWipedBarsRestoration", allowOneDWipedBarsRestoration));
  }
  if (allowQRMicroQrRestoration != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowQRMicroQrRestoration", allowQRMicroQrRestoration));
  }
  if (allowRegularImage != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowRegularImage", allowRegularImage));
  }
  if (allowSaltAndPepperFiltering != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowSaltAndPepperFiltering", allowSaltAndPepperFiltering));
  }
  if (allowWhiteSpotsRemoving != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowWhiteSpotsRemoving", allowWhiteSpotsRemoving));
  }
  if (checkMore1DVariants != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "CheckMore1DVariants", checkMore1DVariants));
  }
  if (fastScanOnly != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "FastScanOnly", fastScanOnly));
  }
  if (allowAdditionalRestorations != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AllowAdditionalRestorations", allowAdditionalRestorations));
  }
  if (regionLikelihoodThresholdPercent != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "",
        "RegionLikelihoodThresholdPercent",
        regionLikelihoodThresholdPercent));
  }
  if (scanWindowSizes != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "multi", "ScanWindowSizes", scanWindowSizes));
  }
  if (similarity != null) {
    queryParams.addAll(
        convertParametersForCollectionFormat("", "Similarity", similarity));
  }
  if (skipDiagonalSearch != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "SkipDiagonalSearch", skipDiagonalSearch));
  }
  if (readTinyBarcodes != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "ReadTinyBarcodes", readTinyBarcodes));
  }
  if (australianPostEncodingTable != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "", "AustralianPostEncodingTable", australianPostEncodingTable));
  }
  if (ignoreEndingFillingPatternsForCTable != null) {
    queryParams.addAll(convertParametersForCollectionFormat(
        "",
        "IgnoreEndingFillingPatternsForCTable",
        ignoreEndingFillingPatternsForCTable));
  }
  if (url != null) {
    queryParams.addAll(convertParametersForCollectionFormat("", "url", url));
  }

  final List<String> contentTypes = [
    "multipart/form-data",
    "application/x-www-form-urlencoded",
    "application/octet-stream"
  ];

  final String contentType =
      contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
  final List<String> authNames = ["JWT"];

  if (contentType.startsWith("multipart/form-data")) {
    bool hasFields = false;
    MultipartRequest? mp;

    mp = MultipartRequest('POST', Uri.parse(requestPath));
    // ignore: unnecessary_null_comparison
    if (image != null) {
      hasFields = true;
      mp.fields['image'] = image.field;
      mp.files.add(image);
    }

    if (hasFields) {
      postBody = mp;
    }
  } else {}

  final response = await apiClient.invokeAPI(requestPath, 'POST', queryParams,
      postBody, headerParams, formParams, contentType, authNames);

  if (response.statusCode >= 400) {
    throw ApiException(response.statusCode, response.body);
  } else {
    return apiClient.deserialize(response.body, 'BarcodeResponseList')
        as BarcodeResponseList;
  }
}