postBarcodeRecognizeFromUrlOrContent method

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

  // 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 (types != null) {
    queryParams.addAll(
        convertParametersForCollectionFormat("multi", "Types", types));
  }
  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;
    MultipartRequestPlus? mp;

    mp = MultipartRequestPlus('POST', Uri.parse(requestPath));
    if (image != null) {
      hasFields = true;
      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;
  }
}