From 3440980a33d8ac12df205dd1bbe86c40d6a75d0d Mon Sep 17 00:00:00 2001 From: SimoneMariaRomeo <180769497+SimoneMariaRomeo@users.noreply.github.com> Date: Fri, 15 May 2026 11:59:36 +0700 Subject: [PATCH 1/3] Fix Windows scanner format selection --- lib/assets/barcode.html | 54 ++++++++++++++++++++++++++++++++------ lib/screens/io_device.dart | 5 +++- lib/screens/window.dart | 12 +++++++-- 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/lib/assets/barcode.html b/lib/assets/barcode.html index 314447e..d6baf2b 100644 --- a/lib/assets/barcode.html +++ b/lib/assets/barcode.html @@ -22,7 +22,42 @@
- \ No newline at end of file + diff --git a/lib/screens/io_device.dart b/lib/screens/io_device.dart index 65ac12b..d80b3e1 100644 --- a/lib/screens/io_device.dart +++ b/lib/screens/io_device.dart @@ -53,10 +53,13 @@ class BarcodeScanner extends StatelessWidget { cancelButtonText: cancelButtonText, isShowFlashIcon: isShowFlashIcon, scanType: scanType, + cameraFace: cameraFace, onScanned: onScanned, appBarTitle: appBarTitle, centerTitle: centerTitle, + barcodeAppBar: barcodeAppBar, delayMillis: delayMillis, + onClose: onClose, ); } else { /// Scan Android and ios barcode scanner with flutter_barcode_scanner @@ -86,7 +89,7 @@ class BarcodeScanner extends StatelessWidget { } } - _scanBarcodeForMobileAndTabDevices(ScanMode scanMode) async { + Future _scanBarcodeForMobileAndTabDevices(ScanMode scanMode) async { String barcode = await FlutterBarcodeScanner.scanBarcode( lineColor, cancelButtonText, diff --git a/lib/screens/window.dart b/lib/screens/window.dart index a077ea5..291e3e9 100644 --- a/lib/screens/window.dart +++ b/lib/screens/window.dart @@ -126,7 +126,12 @@ class WindowBarcodeScanner extends StatelessWidget { String getAssetFileUrl({required String asset}) { final assetsDirectory = p.join(p.dirname(Platform.resolvedExecutable), 'data', 'flutter_assets', asset); - return Uri.file(assetsDirectory).toString(); + return Uri.file(assetsDirectory).replace( + queryParameters: { + 'scanType': scanType.name, + 'cameraFace': cameraFace.name, + }, + ).toString(); } Future initPlatformState( @@ -155,7 +160,10 @@ class WindowBarcodeScanner extends StatelessWidget { return true; } - _buildAppBar(WebviewController controller, BuildContext context) { + PreferredSizeWidget? _buildAppBar( + WebviewController controller, + BuildContext context, + ) { if (appBarTitle == null && barcodeAppBar == null) { return null; } From dbe21469e1cea4428b19b404960c6a4017108925 Mon Sep 17 00:00:00 2001 From: SimoneMariaRomeo <180769497+SimoneMariaRomeo@users.noreply.github.com> Date: Fri, 15 May 2026 14:35:44 +0700 Subject: [PATCH 2/3] Address scanner HTML code smells --- lib/assets/barcode.html | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/assets/barcode.html b/lib/assets/barcode.html index d6baf2b..153ac15 100644 --- a/lib/assets/barcode.html +++ b/lib/assets/barcode.html @@ -47,7 +47,7 @@ }; supportedFormats.default = supportedFormats.qr.concat(supportedFormats.barcode); - const params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(globalThis.location.search); const requestedScanType = params.get("scanType") || "default"; const requestedCameraFace = params.get("cameraFace") || "back"; const formatsToSupport = @@ -62,15 +62,15 @@ const qrCodeSuccessCallback = (decodedText, decodedResult) => { html5QrCode.stop(); /* handle success for web */ - window.parent.postMessage(decodedText, "*"); + globalThis.parent.postMessage(decodedText, "*"); /* handle success for window */ - if (window.chrome && window.chrome.webview) { + if (globalThis.chrome && globalThis.chrome.webview) { var param = { "methodName": "successCallback", "data": decodedText } - window.chrome.webview.postMessage(param); + globalThis.chrome.webview.postMessage(param); } }; @@ -84,17 +84,23 @@ }; // If you want to prefer back camera - html5QrCode.start({ - facingMode: cameraFacingMode - }, config, qrCodeSuccessCallback, function(errorMessage) { - console.debug("Barcode scan frame did not decode", errorMessage); - }).catch(function(error) { - console.error("Unable to start barcode scanner", error); - }); + async function startScanner() { + try { + await html5QrCode.start({ + facingMode: cameraFacingMode + }, config, qrCodeSuccessCallback, function(errorMessage) { + console.debug("Barcode scan frame did not decode", errorMessage); + }); + } catch (error) { + console.error("Unable to start barcode scanner", error); + } + } + + startScanner(); //Window event listener - if (window.chrome && window.chrome.webview) { - window.chrome.webview.addEventListener('message', function(e) { + if (globalThis.chrome && globalThis.chrome.webview) { + globalThis.chrome.webview.addEventListener('message', function(e) { let data = JSON.parse(JSON.stringify(e.data)); if (data.event === "close") { html5QrCode.stop(); From 32729efafd9034fa888ddc344807e959b2e68147 Mon Sep 17 00:00:00 2001 From: SimoneMariaRomeo <180769497+SimoneMariaRomeo@users.noreply.github.com> Date: Fri, 15 May 2026 14:37:57 +0700 Subject: [PATCH 3/3] Clear scanner HTML Sonar warning --- lib/assets/barcode.html | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/assets/barcode.html b/lib/assets/barcode.html index 153ac15..8954e3a 100644 --- a/lib/assets/barcode.html +++ b/lib/assets/barcode.html @@ -20,8 +20,9 @@
-