mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
Fix QR scanner to accept fountain coding for BC-UR codes (#3048)
* fix: use fountain decoder to determine UR scanning progress * fix: use fountain encoder for cupcake * fix build * fix crash * revert encoder changes
This commit is contained in:
@@ -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<BarcodeScannerSimple> {
|
||||
|
||||
List<String> urCodes = [];
|
||||
late var ur = URQRToURQRData(urCodes);
|
||||
final decoder = URDecoder();
|
||||
|
||||
void _handleBarcode(BarcodeCapture barcodes) {
|
||||
try {
|
||||
@@ -70,11 +72,12 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
|
||||
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<BarcodeScannerSimple> {
|
||||
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<BarcodeScannerSimple> {
|
||||
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(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user