From 119cc4993aa0fa07d669445a91ca40b782973073 Mon Sep 17 00:00:00 2001 From: Mark M2 Macbook Date: Sun, 15 Nov 2026 10:04:39 +0100 Subject: [PATCH] =?UTF-8?q?fix=20modalit=C3=A0=20normale=20e=20precisione?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/screens/scanner_screen.dart | 63 ++++++++++++------- app/pubspec.yaml | 2 +- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/app/lib/features/scanner/presentation/screens/scanner_screen.dart b/app/lib/features/scanner/presentation/screens/scanner_screen.dart index 29eea13..a67d40b 100644 --- a/app/lib/features/scanner/presentation/screens/scanner_screen.dart +++ b/app/lib/features/scanner/presentation/screens/scanner_screen.dart @@ -245,13 +245,45 @@ class _ScannerScreenState extends State _precisionTargetIndex = null; }); } - final barcodes = capture.barcodes; - if (barcodes.isEmpty) return; - final first = barcodes.first; - final rawValue = first.rawValue ?? first.displayValue; - if (rawValue == null || rawValue.trim().isEmpty) return; - final formatName = first.format.name.replaceAll('BarcodeFormat.', ''); - context.read().processBarcode(rawValue, format: formatName); + + final standardReticle = ScannerReticleGeometry.scanRect( + _viewportSize, + ScanAimMode.standard, + ); + + final items = BarcodeGeometry.mapCaptureToItems( + capture: capture, + widgetSize: _viewportSize, + deviceOrientation: deviceOrientation, + ); + + if (items.isNotEmpty && standardReticle != null) { + // Check barcodes whose center or bounding box falls inside the reticle + final inside = items.where((item) => + standardReticle.contains(item.center) || + standardReticle.overlaps(item.boundingRect)).toList(); + if (inside.isEmpty) return; + + // Pick the barcode closest to the reticle center + inside.sort((a, b) => + (a.center - standardReticle.center).distanceSquared.compareTo( + (b.center - standardReticle.center).distanceSquared)); + + final best = inside.first; + context.read().processBarcode( + best.code, + format: best.format, + ); + } else { + // Fallback if geometric mapping is unavailable + final barcodes = capture.barcodes; + if (barcodes.isEmpty) return; + final first = barcodes.first; + final rawValue = first.rawValue ?? first.displayValue; + if (rawValue == null || rawValue.trim().isEmpty) return; + final formatName = first.format.name.replaceAll('BarcodeFormat.', ''); + context.read().processBarcode(rawValue, format: formatName); + } case ScanAimMode.precision: final items = BarcodeGeometry.mapCaptureToItems( @@ -266,7 +298,7 @@ class _ScannerScreenState extends State final target = BarcodeGeometry.selectPrecisionTarget( items: items, crosshairCenter: crosshairCenter, - hitRadius: 16.0, + hitRadius: 24.0, ); _updateLiveArItems(items, precisionTargetIndex: target?.index); @@ -477,7 +509,7 @@ class _ScannerScreenState extends State } } - Future _handleTapToFocus(TapUpDetails details) async { + void _handleTapToFocus(TapUpDetails details) { if (_frozenSnapshot != null || _viewportSize.isEmpty || !_scannerController.value.isRunning) { @@ -485,9 +517,6 @@ class _ScannerScreenState extends State } final local = details.localPosition; - final rx = (local.dx / _viewportSize.width).clamp(0.0, 1.0); - final ry = (local.dy / _viewportSize.height).clamp(0.0, 1.0); - _focusRingTimer?.cancel(); setState(() { _focusRingPosition = local; @@ -498,9 +527,7 @@ class _ScannerScreenState extends State } }); - try { - await _scannerController.setFocusPoint(Offset(rx, ry)); - } catch (_) {} + _feedbackService.triggerSelection(); } void _toggleTorch() { @@ -537,10 +564,6 @@ class _ScannerScreenState extends State return LayoutBuilder( builder: (context, constraints) { _viewportSize = constraints.biggest; - final scanWindow = ScannerReticleGeometry.scanRect( - _viewportSize, - aimMode, - ); final topSafe = MediaQuery.paddingOf(context).top + 124.0; final bottomReserved = (lastScan != null ? 250.0 : 165.0) + @@ -575,8 +598,6 @@ class _ScannerScreenState extends State }, child: MobileScanner( controller: _scannerController, - scanWindow: scanWindow, - scanWindowUpdateThreshold: 4.0, onDetect: _onDetect, ), ), diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 28ba261..375863f 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.3+4 +version: 1.0.4+5 environment: sdk: ^3.13.4