fix null check when user exits out of qr code scanner (#2002)

This commit is contained in:
cyan 2025-02-05 02:40:06 +01:00 committed by GitHub
parent e88b6b2bcf
commit 1dc7f9309a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 10 additions and 4 deletions

View file

@ -12,7 +12,7 @@ import 'package:flutter/scheduler.dart';
var isQrScannerShown = false;
Future<String> presentQRScanner(BuildContext context) async {
Future<String?> presentQRScanner(BuildContext context) async {
isQrScannerShown = true;
try {
final result = await Navigator.of(context).push<String>(
@ -23,7 +23,7 @@ Future<String> presentQRScanner(BuildContext context) async {
),
);
isQrScannerShown = false;
return result!;
return result;
} catch (e) {
isQrScannerShown = false;
rethrow;

View file

@ -100,6 +100,7 @@ class AnimatedURPage extends BasePage {
switch (urQrType) {
case "ur:xmr-txunsigned": // ur:xmr-txsigned
final ur = await presentQRScanner(context);
if (ur == null) return;
final result = await monero!.commitTransactionUR(animatedURmodel.wallet, ur);
if (result) {
Navigator.of(context).pop(true);
@ -107,6 +108,7 @@ class AnimatedURPage extends BasePage {
break;
case "ur:xmr-output": // xmr-keyimage
final ur = await presentQRScanner(context);
if (ur == null) return;
final result = await monero!.importKeyImagesUR(animatedURmodel.wallet, ur);
if (result) {
Navigator.of(context).pop(true);

View file

@ -233,6 +233,7 @@ class AddressTextField<T extends Currency> extends StatelessWidget{
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
final code = await presentQRScanner(context);
if (code == null) return;
if (code.isEmpty) {
return;
}

View file

@ -215,7 +215,9 @@ abstract class NodeCreateOrEditViewModelBase with Store {
bool isCameraPermissionGranted =
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
String code = await presentQRScanner(context);
String? code = await presentQRScanner(context);
if (code == null) throw Exception("Unexpected QR code value: aborted");
if (code.isEmpty) {
throw Exception('Unexpected scan QR code value: value is empty');
}

View file

@ -89,7 +89,8 @@ class WalletRestoreFromQRCode {
}
static Future<RestoredWallet> scanQRCodeForRestoring(BuildContext context) async {
String code = await presentQRScanner(context);
String? code = await presentQRScanner(context);
if (code == null) throw Exception("Unexpected scan QR code value: aborted");
if (code.isEmpty) throw Exception('Unexpected scan QR code value: value is empty');
WalletType? walletType;