fix null check when user exits out of qr code scanner (#2002)
cyan committed
Feb 5, 2025 at 02:40 UTC
1dc7f9309a83a1fb79ab90b2847044b6725fbb36
5 files changed
+10
-4
lib/entities/qr_scanner.dart
+2
-2
@@ -12,7 +12,7 @@ import 'package:flutter/scheduler.dart';
12
13
var isQrScannerShown = false;
14
15
-Future<String> presentQRScanner(BuildContext context) async {
15
+Future<String?> presentQRScanner(BuildContext context) async {
16
isQrScannerShown = true;
17
try {
18
final result = await Navigator.of(context).push<String>(
@@ -23,7 +23,7 @@ Future<String> presentQRScanner(BuildContext context) async {
23
),
24
);
25
isQrScannerShown = false;
26
- return result!;
26
+ return result;
27
} catch (e) {
28
isQrScannerShown = false;
29
rethrow;
lib/src/screens/ur/animated_ur_page.dart
+2
@@ -100,6 +100,7 @@ class AnimatedURPage extends BasePage {
100
switch (urQrType) {
101
case "ur:xmr-txunsigned": // ur:xmr-txsigned
102
final ur = await presentQRScanner(context);
103
+ if (ur == null) return;
104
final result = await monero!.commitTransactionUR(animatedURmodel.wallet, ur);
105
if (result) {
106
Navigator.of(context).pop(true);
@@ -107,6 +108,7 @@ class AnimatedURPage extends BasePage {
108
break;
109
case "ur:xmr-output": // xmr-keyimage
110
final ur = await presentQRScanner(context);
111
+ if (ur == null) return;
112
final result = await monero!.importKeyImagesUR(animatedURmodel.wallet, ur);
113
if (result) {
114
Navigator.of(context).pop(true);
lib/src/widgets/address_text_field.dart
+1
@@ -233,6 +233,7 @@ class AddressTextField<T extends Currency> extends StatelessWidget{
233
await PermissionHandler.checkPermission(Permission.camera, context);
234
if (!isCameraPermissionGranted) return;
235
final code = await presentQRScanner(context);
236
+ if (code == null) return;
237
if (code.isEmpty) {
238
return;
239
}
lib/view_model/node_list/node_create_or_edit_view_model.dart
+3
-1
@@ -215,7 +215,9 @@ abstract class NodeCreateOrEditViewModelBase with Store {
215
bool isCameraPermissionGranted =
216
await PermissionHandler.checkPermission(Permission.camera, context);
217
if (!isCameraPermissionGranted) return;
218
- String code = await presentQRScanner(context);
218
+ String? code = await presentQRScanner(context);
219
+ if (code == null) throw Exception("Unexpected QR code value: aborted");
220
+
221
if (code.isEmpty) {
222
throw Exception('Unexpected scan QR code value: value is empty');
223
}
lib/view_model/restore/wallet_restore_from_qr_code.dart
+2
-1
@@ -89,7 +89,8 @@ class WalletRestoreFromQRCode {
89
}
90
91
static Future<RestoredWallet> scanQRCodeForRestoring(BuildContext context) async {
92
- String code = await presentQRScanner(context);
92
+ String? code = await presentQRScanner(context);
93
+ if (code == null) throw Exception("Unexpected scan QR code value: aborted");
94
if (code.isEmpty) throw Exception('Unexpected scan QR code value: value is empty');
95
96
WalletType? walletType;