detectBarcodesFromImage static method
Future<BarcodeScanningResult>
detectBarcodesFromImage(
- MethodChannel channel,
- Uri file, {
- List<
BarcodeFormat> barcodeFormats = const <BarcodeFormat>[], - BarcodeAdditionalParameters? additionalParameters,
- List<
BarcodeDocumentFormat> acceptedDocumentFormats = const <BarcodeDocumentFormat>[],
Detect barcodes from image file uri.
The Barcode Scanner is able to recognize 1D- and 2D-barcodes.
barcodeFormats
barcode type(s) that should be recognized.
acceptedDocumentFormats
barcode document type(s) that should be recognized.
Implementation
static Future<BarcodeScanningResult> detectBarcodesFromImage(
MethodChannel channel,
Uri file, {
List<BarcodeFormat> barcodeFormats = const <BarcodeFormat>[],
BarcodeAdditionalParameters? additionalParameters,
List<BarcodeDocumentFormat> acceptedDocumentFormats =
const <BarcodeDocumentFormat>[],
}) async {
var barcodeResult = BarcodeScanningResult.error(
"Barcode detection failed"); // default error message initialisation
try {
List<Uri> list = [file];
var result = await detectBarcodesFromImages(
channel,
list,
barcodeFormats: barcodeFormats,
additionalParameters: additionalParameters,
acceptedDocumentFormats: acceptedDocumentFormats,
);
if (result.operationResult == OperationResult.SUCCESS) {
if (result.barcodeResults.isNotEmpty) {
barcodeResult = result.barcodeResults.first;
}
} else {
barcodeResult.message = result.message;
}
return barcodeResult;
} catch (e) {
Logger.root.severe(e);
barcodeResult.message = e.toString();
return barcodeResult;
}
}