Reputation: 1473
I am using simple_barcode_scanner
On iOS, the barcode scanner does not close immediately after detecting a barcode. Instead, it only closes when the camera is moved away from the barcode. However, on Android, the scanner behaves correctly, closing as soon as a barcode is detected.
Expected Behavior: The scanner should automatically close as soon as a barcode is scanned, similar to Android behavior.
Actual Behavior: On Android: The scanner correctly detects a barcode and closes immediately. On iOS: The scanner remains open and only closes when the camera is moved away from the barcode.
Steps to Reproduce: Create a new Flutter project and add simple_barcode_scanner.
Implement the scanner using the following code:
scan() async {
String? barcodeScanRes = await SimpleBarcodeScanner.scanBarcode(
context,
barcodeAppBar: const BarcodeAppBar(
appBarTitle: 'Scan',
centerTitle: false,
enableBackButton: true,
backButtonIcon: Icon(Icons.arrow_back_ios),
),
isShowFlashIcon: true,
delayMillis: 2000,
cameraFace: CameraFace.back,
lineColor: "#E81A5E",
);
}
Run the app on both Android and iOS devices. Scan a barcode.
Observe the behavior: On Android: Scanner detects and closes immediately. On iOS: Scanner remains open until the camera moves away from the barcode.
Flutter version:
[√] Flutter Channel stable, 3.29.1
Upvotes: 0
Views: 25
Reputation: 69
This is because the behavior of barcode scanners can vary between platforms due to differences in how camera and scanning APIs are implemented.
Try Below Solutions:
Implement a Workaround: As a temporary solution, you can programmatically close the scanner once a barcode is detected by modifying the package's source code or handling the state within your application.
Explore Alternative Packages: Consider using other barcode scanning packages that offer more consistent behavior across platforms. One such package is mobile_scanner
, or similar to this.
Upvotes: 0