Просмотр исходного кода

Updated barcode_format.dart to null-safety.

flutter-beta
Julian Steenbakker 5 лет назад
Родитель
Сommit
92e8abedce
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 16E437C7A3D94250
3 измененных файлов: 12 добавлений и 46 удалений
  1. +3
    -3
      lib/src/qr_code_scanner.dart
  2. +2
    -5
      lib/src/qr_scanner_overlay_shape.dart
  3. +7
    -38
      lib/src/types/barcode_format.dart

+ 3
- 3
lib/src/qr_code_scanner.dart Просмотреть файл

@@ -185,12 +185,12 @@ class QRViewController {
case 'onRecognizeQR': case 'onRecognizeQR':
if (call.arguments != null) { if (call.arguments != null) {
final args = call.arguments as Map; 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. // Raw bytes are only supported by Android.
final rawBytes = args['rawBytes'] as List<int>?; final rawBytes = args['rawBytes'] as List<int>?;
final format = BarcodeTypesExtension.fromString(rawType); final format = BarcodeTypesExtension.fromString(rawType);
if (format != null) {
if (format != BarcodeFormat.unknown) {
final barcode = Barcode(code, format, rawBytes); final barcode = Barcode(code, format, rawBytes);
_scanUpdateController.sink.add(barcode); _scanUpdateController.sink.add(barcode);
} else { } else {


+ 2
- 5
lib/src/qr_scanner_overlay_shape.dart Просмотреть файл

@@ -11,10 +11,7 @@ class QrScannerOverlayShape extends ShapeBorder {
this.borderLength = 40, this.borderLength = 40,
this.cutOutSize = 250, this.cutOutSize = 250,
this.cutOutBottomOffset = 0, 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}"); "Border can't be larger than ${cutOutSize / 2 + borderWidth * 2}");


final Color borderColor; final Color borderColor;
@@ -68,7 +65,7 @@ class QrScannerOverlayShape extends ShapeBorder {
final _borderLength = borderLength > cutOutSize / 2 + borderWidth * 2 final _borderLength = borderLength > cutOutSize / 2 + borderWidth * 2
? borderWidthSize / 2 ? borderWidthSize / 2
: borderLength; : borderLength;
final _cutOutSize = cutOutSize != null && cutOutSize < width
final _cutOutSize = cutOutSize < width
? cutOutSize ? cutOutSize
: width - borderOffset; : width - borderOffset;




+ 7
- 38
lib/src/types/barcode_format.dart Просмотреть файл

@@ -53,7 +53,10 @@ enum BarcodeFormat {
upcE, upcE,


/// UPC/EAN extension format. Not a stand-alone format. /// UPC/EAN extension format. Not a stand-alone format.
upcEanExtension
upcEanExtension,

/// Unknown
unknown
} }


extension BarcodeTypesExtension on BarcodeFormat { extension BarcodeTypesExtension on BarcodeFormat {
@@ -61,61 +64,44 @@ extension BarcodeTypesExtension on BarcodeFormat {
return index; return index;
} }


static BarcodeFormat? fromString(String? format) {
static BarcodeFormat fromString(String format) {
switch (format) { switch (format) {
case 'AZTEC': case 'AZTEC':
return BarcodeFormat.aztec; return BarcodeFormat.aztec;
break;
case 'CODABAR': case 'CODABAR':
return BarcodeFormat.codabar; return BarcodeFormat.codabar;
break;
case 'CODE_39': case 'CODE_39':
return BarcodeFormat.code39; return BarcodeFormat.code39;
break;
case 'CODE_93': case 'CODE_93':
return BarcodeFormat.code93; return BarcodeFormat.code93;
break;
case 'CODE_128': case 'CODE_128':
return BarcodeFormat.code128; return BarcodeFormat.code128;
break;
case 'DATA_MATRIX': case 'DATA_MATRIX':
return BarcodeFormat.dataMatrix; return BarcodeFormat.dataMatrix;
break;
case 'EAN_8': case 'EAN_8':
return BarcodeFormat.ean8; return BarcodeFormat.ean8;
break;
case 'EAN_13': case 'EAN_13':
return BarcodeFormat.ean13; return BarcodeFormat.ean13;
break;
case 'ITF': case 'ITF':
return BarcodeFormat.itf; return BarcodeFormat.itf;
break;
case 'MAXICODE': case 'MAXICODE':
return BarcodeFormat.maxicode; return BarcodeFormat.maxicode;
break;
case 'PDF_417': case 'PDF_417':
return BarcodeFormat.pdf417; return BarcodeFormat.pdf417;
break;
case 'QR_CODE': case 'QR_CODE':
return BarcodeFormat.qrcode; return BarcodeFormat.qrcode;
break;
case 'RSS14': case 'RSS14':
return BarcodeFormat.rss14; return BarcodeFormat.rss14;
break;
case 'RSS_EXPANDED': case 'RSS_EXPANDED':
return BarcodeFormat.rssExpanded; return BarcodeFormat.rssExpanded;
break;
case 'UPC_A': case 'UPC_A':
return BarcodeFormat.upcA; return BarcodeFormat.upcA;
break;
case 'UPC_E': case 'UPC_E':
return BarcodeFormat.upcE; return BarcodeFormat.upcE;
break;
case 'UPC_EAN_EXTENSION': case 'UPC_EAN_EXTENSION':
return BarcodeFormat.upcEanExtension; return BarcodeFormat.upcEanExtension;
break;
default: default:
return null;
return BarcodeFormat.unknown;
} }
} }


@@ -123,57 +109,40 @@ extension BarcodeTypesExtension on BarcodeFormat {
switch (this) { switch (this) {
case BarcodeFormat.aztec: case BarcodeFormat.aztec:
return 'AZTEC'; return 'AZTEC';
break;
case BarcodeFormat.codabar: case BarcodeFormat.codabar:
return 'CODABAR'; return 'CODABAR';
break;
case BarcodeFormat.code39: case BarcodeFormat.code39:
return 'CODE_39'; return 'CODE_39';
break;
case BarcodeFormat.code93: case BarcodeFormat.code93:
return 'CODE_93'; return 'CODE_93';
break;
case BarcodeFormat.code128: case BarcodeFormat.code128:
return 'CODE_128'; return 'CODE_128';
break;
case BarcodeFormat.dataMatrix: case BarcodeFormat.dataMatrix:
return 'DATA_MATRIX'; return 'DATA_MATRIX';
break;
case BarcodeFormat.ean8: case BarcodeFormat.ean8:
return 'EAN_8'; return 'EAN_8';
break;
case BarcodeFormat.ean13: case BarcodeFormat.ean13:
return 'EAN_13'; return 'EAN_13';
break;
case BarcodeFormat.itf: case BarcodeFormat.itf:
return 'ITF'; return 'ITF';
break;
case BarcodeFormat.maxicode: case BarcodeFormat.maxicode:
return 'MAXICODE'; return 'MAXICODE';
break;
case BarcodeFormat.pdf417: case BarcodeFormat.pdf417:
return 'PDF_417'; return 'PDF_417';
break;
case BarcodeFormat.qrcode: case BarcodeFormat.qrcode:
return 'QR_CODE'; return 'QR_CODE';
break;
case BarcodeFormat.rss14: case BarcodeFormat.rss14:
return 'RSS14'; return 'RSS14';
break;
case BarcodeFormat.rssExpanded: case BarcodeFormat.rssExpanded:
return 'RSS_EXPANDED'; return 'RSS_EXPANDED';
break;
case BarcodeFormat.upcA: case BarcodeFormat.upcA:
return 'UPC_A'; return 'UPC_A';
break;
case BarcodeFormat.upcE: case BarcodeFormat.upcE:
return 'UPC_E'; return 'UPC_E';
break;
case BarcodeFormat.upcEanExtension: case BarcodeFormat.upcEanExtension:
return 'UPC_EAN_EXTENSION'; return 'UPC_EAN_EXTENSION';
break;
default: default:
return 'NOT_VALID';
return 'UNKNOWN';
} }
} }
} }

Загрузка…
Отмена
Сохранить