scanBarcode method
Future<BarcodeResponseList>
scanBarcode(
- MultipartFile imageFile, {
- List<
DecodeBarcodeType> ? decodeTypes, - int? timeout,
- String? checksumValidation,
Quickly scan a barcode from an image.
Implementation
Future<BarcodeResponseList> scanBarcode(MultipartFile imageFile,
{List<DecodeBarcodeType>? decodeTypes,
int? timeout,
String? checksumValidation}) async {
// ignore: prefer_final_locals
Object? postBody;
// create path and map variables
final String requestPath = "/barcode/scan".replaceAll("{format}", "json");
// query params
final List<QueryParam> queryParams = [];
final Map<String, String> headerParams = {};
final Map<String, String> formParams = {};
final List<String> contentTypes = ["multipart/form-data"];
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));
hasFields = true;
mp.files.add(imageFile);
if (decodeTypes != null) {
hasFields = true;
final List<String> stringValues =
decodeTypes.map((i) => parameterToString(i)).toList();
mp.fields['decodeTypes'] = stringValues;
}
if (timeout != null) {
hasFields = true;
mp.fields['timeout'] = [parameterToString(timeout)];
}
if (checksumValidation != null) {
hasFields = true;
mp.fields['checksumValidation'] = [
parameterToString(checksumValidation)
];
}
if (hasFields) {
postBody = mp;
}
} else {
if (decodeTypes != null) {
formParams['decodeTypes'] = parameterToString(decodeTypes);
}
if (timeout != null) {
formParams['timeout'] = parameterToString(timeout);
}
if (checksumValidation != null) {
formParams['checksumValidation'] =
parameterToString(checksumValidation);
}
}
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;
}
}