scanBarcodeFromImage method
- BuildContext context
Scans the given image for barcodes.
This method displays an image picker to the user and asks them to select
an image. The selected image is then processed to detect any barcodes
present. If a barcode is detected, its raw value is returned as a string.
If no barcodes are detected or an error occurs during processing, null
is returned.
Shows an error toast if an exception occurs during barcode processing or if the detected barcode is not a valid number.
context The build context of the widget that called this method.
Returns the raw value of the first detected barcode, or '-404' if no barcodes are found or an error occurs.
Implementation
Future<String> scanBarcodeFromImage(final BuildContext context) async {
try {
final image = await _pickGalleryImage();
final barcode = await _getBarcodeFromImage(image);
return barcode;
} catch (e) {
showErrorToast('حدث خطاء اثناء تحليل الصورة: ${e.toString()}');
return '-404';
}
}