diff --git a/lib/entities/qr_scanner.dart b/lib/entities/qr_scanner.dart index 31353a8f8..e62a625b7 100644 --- a/lib/entities/qr_scanner.dart +++ b/lib/entities/qr_scanner.dart @@ -7,6 +7,7 @@ import 'package:cw_core/utils/print_verbose.dart'; import 'package:fast_scanner/fast_scanner.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; +import 'package:ur/ur_decoder.dart'; var isQrScannerShown = false; @@ -42,6 +43,7 @@ class _BarcodeScannerSimpleState extends State { List urCodes = []; late var ur = URQRToURQRData(urCodes); + final decoder = URDecoder(); void _handleBarcode(BarcodeCapture barcodes) { try { @@ -70,11 +72,12 @@ class _BarcodeScannerSimpleState extends State { if (barcode.rawValue?.trim().isEmpty ?? false == false) continue; if (barcode.rawValue!.startsWith("ur:")) { if (urCodes.contains(barcode.rawValue)) continue; + decoder.receivePart(barcode.rawValue!); setState(() { urCodes.add(barcode.rawValue!); ur = URQRToURQRData(urCodes); }); - if (ur.progress == 1) { + if (decoder.estimatedPercentComplete() == 1) { setState(() { popped = true; }); @@ -118,10 +121,10 @@ class _BarcodeScannerSimpleState extends State { onDetect: _handleBarcode, controller: ctrl, ), - if (ur.inputs.length != 0) + if (decoder.expectedPartCount() != null) Center( child: Text( - "${ur.inputs.length}/${ur.count}", + "${decoder.processedPartsCount()}/${decoder.expectedPartCount()!}", style: Theme.of(context) .textTheme .displayLarge @@ -136,10 +139,10 @@ class _BarcodeScannerSimpleState extends State { child: CustomPaint( painter: ProgressPainter( urQrProgress: URQrProgress( - expectedPartCount: ur.count - 1, - processedPartsCount: ur.inputs.length, - receivedPartIndexes: _urParts(), - percentage: ur.progress, + expectedPartCount: decoder.expectedPartCount() ?? 0, + processedPartsCount: decoder.processedPartsCount(), + receivedPartIndexes: decoder.receivedPartIndexes().toList(), + percentage: decoder.estimatedPercentComplete(), ), ), ),