From 92e8abedce1aced25f16c98edf64d694b40e5cde Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Sun, 14 Mar 2021 19:37:29 +0100 Subject: [PATCH] Updated barcode_format.dart to null-safety. --- lib/src/qr_code_scanner.dart | 6 ++-- lib/src/qr_scanner_overlay_shape.dart | 7 ++--- lib/src/types/barcode_format.dart | 45 +++++---------------------- 3 files changed, 12 insertions(+), 46 deletions(-) diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 6e25f13..23b7589 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -185,12 +185,12 @@ class QRViewController { case 'onRecognizeQR': if (call.arguments != null) { final args = call.arguments as Map; - final code = args['code'] as String?; - final rawType = args['type'] as String?; + final code = args['code'] as String; + final rawType = args['type'] as String; // Raw bytes are only supported by Android. final rawBytes = args['rawBytes'] as List?; final format = BarcodeTypesExtension.fromString(rawType); - if (format != null) { + if (format != BarcodeFormat.unknown) { final barcode = Barcode(code, format, rawBytes); _scanUpdateController.sink.add(barcode); } else { diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index d890788..dcb5906 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -11,10 +11,7 @@ class QrScannerOverlayShape extends ShapeBorder { this.borderLength = 40, this.cutOutSize = 250, this.cutOutBottomOffset = 0, - }) : assert( - cutOutSize != null ?? - cutOutSize != null ?? - borderLength <= cutOutSize / 2 + borderWidth * 2, + }) : assert( borderLength <= cutOutSize / 2 + borderWidth * 2, "Border can't be larger than ${cutOutSize / 2 + borderWidth * 2}"); final Color borderColor; @@ -68,7 +65,7 @@ class QrScannerOverlayShape extends ShapeBorder { final _borderLength = borderLength > cutOutSize / 2 + borderWidth * 2 ? borderWidthSize / 2 : borderLength; - final _cutOutSize = cutOutSize != null && cutOutSize < width + final _cutOutSize = cutOutSize < width ? cutOutSize : width - borderOffset; diff --git a/lib/src/types/barcode_format.dart b/lib/src/types/barcode_format.dart index e32756b..49bcee2 100644 --- a/lib/src/types/barcode_format.dart +++ b/lib/src/types/barcode_format.dart @@ -53,7 +53,10 @@ enum BarcodeFormat { upcE, /// UPC/EAN extension format. Not a stand-alone format. - upcEanExtension + upcEanExtension, + + /// Unknown + unknown } extension BarcodeTypesExtension on BarcodeFormat { @@ -61,61 +64,44 @@ extension BarcodeTypesExtension on BarcodeFormat { return index; } - static BarcodeFormat? fromString(String? format) { + static BarcodeFormat fromString(String format) { switch (format) { case 'AZTEC': return BarcodeFormat.aztec; - break; case 'CODABAR': return BarcodeFormat.codabar; - break; case 'CODE_39': return BarcodeFormat.code39; - break; case 'CODE_93': return BarcodeFormat.code93; - break; case 'CODE_128': return BarcodeFormat.code128; - break; case 'DATA_MATRIX': return BarcodeFormat.dataMatrix; - break; case 'EAN_8': return BarcodeFormat.ean8; - break; case 'EAN_13': return BarcodeFormat.ean13; - break; case 'ITF': return BarcodeFormat.itf; - break; case 'MAXICODE': return BarcodeFormat.maxicode; - break; case 'PDF_417': return BarcodeFormat.pdf417; - break; case 'QR_CODE': return BarcodeFormat.qrcode; - break; case 'RSS14': return BarcodeFormat.rss14; - break; case 'RSS_EXPANDED': return BarcodeFormat.rssExpanded; - break; case 'UPC_A': return BarcodeFormat.upcA; - break; case 'UPC_E': return BarcodeFormat.upcE; - break; case 'UPC_EAN_EXTENSION': return BarcodeFormat.upcEanExtension; - break; default: - return null; + return BarcodeFormat.unknown; } } @@ -123,57 +109,40 @@ extension BarcodeTypesExtension on BarcodeFormat { switch (this) { case BarcodeFormat.aztec: return 'AZTEC'; - break; case BarcodeFormat.codabar: return 'CODABAR'; - break; case BarcodeFormat.code39: return 'CODE_39'; - break; case BarcodeFormat.code93: return 'CODE_93'; - break; case BarcodeFormat.code128: return 'CODE_128'; - break; case BarcodeFormat.dataMatrix: return 'DATA_MATRIX'; - break; case BarcodeFormat.ean8: return 'EAN_8'; - break; case BarcodeFormat.ean13: return 'EAN_13'; - break; case BarcodeFormat.itf: return 'ITF'; - break; case BarcodeFormat.maxicode: return 'MAXICODE'; - break; case BarcodeFormat.pdf417: return 'PDF_417'; - break; case BarcodeFormat.qrcode: return 'QR_CODE'; - break; case BarcodeFormat.rss14: return 'RSS14'; - break; case BarcodeFormat.rssExpanded: return 'RSS_EXPANDED'; - break; case BarcodeFormat.upcA: return 'UPC_A'; - break; case BarcodeFormat.upcE: return 'UPC_E'; - break; case BarcodeFormat.upcEanExtension: return 'UPC_EAN_EXTENSION'; - break; default: - return 'NOT_VALID'; + return 'UNKNOWN'; } } }