I’m getting random barcode values when the scanner view closes due to timeout even though no QR code or barcode in front of the camera.
Each time this happens, the detected values are different.
Code :
class _QrCodeScannerScreenState extends State<QrCodeScannerScreen> {
late MobileScannerController _cameraController;
@override
void initState() {
_cameraController = MobileScannerController();
super.initState();
}
@override
void dispose() {
_cameraController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final scrWidth = context.mediaQueryWidth;
final scrHeight = context.mediaQueryHeight;
return Scaffold(
body: Stack(
alignment: Alignment.topCenter,
children: [
Positioned(
child: SizedBox(
height: scrHeight,
width: scrWidth,
child: MobileScanner(
fit: BoxFit.contain,
errorBuilder: (p0, p1) => const SizedBox(),
controller: _cameraController,
onDetect: (capture) async {
log("${capture.barcodes.first.rawValue}first value");
for (final val in capture.barcodes) {
log(
val.rawValue ??
"",
);
}
log("${capture.raw} Raw value");
},
),
),
),
],
),
);
}
}
Output :
[log] 7181710678871first value
[log] 7181710678871
[log] {name: barcode, data: [{calendarEvent: null, contactInfo: null, corners: [{x: 608.0, y: 1363.0}, {x: 611.0, y: 1369.0}, {x: 299.0, y: 1468.0}, {x: 297.0, y: 1462.0}], displayValue: 7181710678871, driverLicense: null, email: null, format: 32, geoPoint: null, phone: null, rawBytes: [55, 49, 56, 49, 55, 49, 48, 54, 55, 56, 56, 55, 49], rawValue: 7181710678871, size: {width: 314.0, height: 105.0}, sms: null, type: 5, url: null, wifi: null}], image: {bytes: null, width: 1440.0, height: 1920.0}} Raw value
version : mobile_scanner: ^7.1.3
asked Nov 3, 2025 at 6:58
Akhil George
1,0461 gold badge10 silver badges33 bronze badges
lang-dart
errorBuildercalled (in case of any error)?