From 07017c47458c7f39085e646b618c17320be02789 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 30 Jul 2021 11:09:01 +1000 Subject: [PATCH] Barcode handler code cleanup --- lib/barcode.dart | 21 ++++++++++----------- pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/barcode.dart b/lib/barcode.dart index 381732ba..ab5c313a 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -292,9 +292,6 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { failureTone(); - // Close the barcode scanner - _controller?.dispose(); - Navigator.of(context).pop(); showSnackIcon( @@ -317,10 +314,6 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { } } - - - - class StockItemScanIntoLocationHandler extends BarcodeHandler { /* * Barcode handler for scanning a provided StockItem into a scanned StockLocation @@ -338,7 +331,16 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { // If the barcode points to a 'stocklocation', great! if (data.containsKey('stocklocation')) { // Extract location information - int location = data['stocklocation']['pk'] as int; + int location = (data['stocklocation']['pk'] ?? -1) as int; + + if (location == -1) { + showSnackIcon( + L10().invalidStockLocation, + success: false, + ); + + return; + } // Transfer stock to specified location final result = await item.transferStock(location); @@ -347,9 +349,6 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { successTone(); - // Close the scanner - _controller?.dispose(); - Navigator.of(context).pop(); showSnackIcon( diff --git a/pubspec.lock b/pubspec.lock index 074151d8..3c2e9310 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -475,7 +475,7 @@ packages: name: qr_code_scanner url: "https://pub.dartlang.org" source: hosted - version: "0.5.1" + version: "0.5.2" quiver: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index df1344ed..fd3f75ce 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,7 +24,7 @@ dependencies: cupertino_icons: ^1.0.3 http: ^0.13.0 cached_network_image: ^3.0.0 # Download and cache remote images - qr_code_scanner: ^0.5.1 # Barcode scanning + qr_code_scanner: ^0.5.2 # Barcode scanning package_info_plus: ^1.0.4 # App information introspection device_info_plus: ^2.1.0 # Information about the device font_awesome_flutter: ^9.1.0 # FontAwesome icon set