Procházet zdrojové kódy

Updated barcode_format.dart to null-safety.

flutter-beta
Julian Steenbakker před 5 roky
rodič
revize
92e8abedce
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 16E437C7A3D94250
3 změnil soubory, kde provedl 12 přidání a 46 odebrání
  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 Zobrazit soubor

@@ -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<int>?;
final format = BarcodeTypesExtension.fromString(rawType);
if (format != null) {
if (format != BarcodeFormat.unknown) {
final barcode = Barcode(code, format, rawBytes);
_scanUpdateController.sink.add(barcode);
} else {


+ 2
- 5
lib/src/qr_scanner_overlay_shape.dart Zobrazit soubor

@@ -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;



+ 7
- 38
lib/src/types/barcode_format.dart Zobrazit soubor

@@ -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';
}
}
}

Načítá se…
Zrušit
Uložit