Pārlūkot izejas kodu

Added documentation.

Added string to barcode format function.
flutter-beta
Julian Steenbakker pirms 5 gadiem
vecāks
revīzija
5a3771a508
Šim parakstam datu bāzē netika atrasta zināma atslēga GPG atslēgas ID: 16E437C7A3D94250
2 mainītis faili ar 77 papildinājumiem un 24 dzēšanām
  1. +18
    -22
      lib/src/qr_code_scanner.dart
  2. +59
    -2
      lib/src/types/barcode_format.dart

+ 18
- 22
lib/src/qr_code_scanner.dart Parādīt failu

@@ -14,7 +14,8 @@ import 'types/features.dart';
typedef QRViewCreatedCallback = void Function(QRViewController);
typedef PermissionSetCallback = void Function(QRViewController, bool);

/// The [QRView] is the view where the camera and the barcode scanner gets displayed.
/// The [QRView] is the view where the camera
/// and the barcode scanner gets displayed.
class QRView extends StatefulWidget {
const QRView({
@required Key key,
@@ -28,11 +29,26 @@ class QRView extends StatefulWidget {
assert(onQRViewCreated != null),
super(key: key);

/// [onQRViewCreated] gets called when the view is created
final QRViewCreatedCallback onQRViewCreated;

/// Use [overlay] to provide an overlay for the view.
/// This can be used to create a certain scan area.
final ShapeBorder overlay;

/// Use [overlayMargin] to provide a margin to [overlay]
final EdgeInsetsGeometry overlayMargin;

/// Set which camera to use on startup.
///
/// [cameraFacing] can either be CameraFacing.front or CameraFacing.back.
/// Defaults to CameraFacing.back
final CameraFacing cameraFacing;

/// Calls the provided [onPermissionSet] callback when the permission is set.
final PermissionSetCallback onPermissionSet;

/// Gives the possibility to show a dialog.
final bool showNativeAlertDialog;

@override
@@ -141,26 +157,6 @@ class _QrCameraSettings {
}
}

const _formatNames = <String, BarcodeFormat>{
'AZTEC': BarcodeFormat.aztec,
'CODABAR': BarcodeFormat.codabar,
'CODE_39': BarcodeFormat.code39,
'CODE_93': BarcodeFormat.code93,
'CODE_128': BarcodeFormat.code128,
'DATA_MATRIX': BarcodeFormat.dataMatrix,
'EAN_8': BarcodeFormat.ean8,
'EAN_13': BarcodeFormat.ean13,
'ITF': BarcodeFormat.itf,
'MAXICODE': BarcodeFormat.maxicode,
'PDF_417': BarcodeFormat.pdf417,
'QR_CODE': BarcodeFormat.qrcode,
'RSS_14': BarcodeFormat.rss14,
'RSS_EXPANDED': BarcodeFormat.rssExpanded,
'UPC_A': BarcodeFormat.upcA,
'UPC_E': BarcodeFormat.upcE,
'UPC_EAN_EXTENSION': BarcodeFormat.upcEanExtension,
};

class QRViewController {
QRViewController._(
MethodChannel channel,
@@ -178,7 +174,7 @@ class QRViewController {
final rawType = args['type'] as String;
// Raw bytes are only supported by Android.
final rawBytes = args['rawBytes'] as List<int>;
final format = _formatNames[rawType];
final format = BarcodeTypesExtension.fromString(rawType);
if (format != null) {
final barcode = Barcode(code, format, rawBytes);
_scanUpdateController.sink.add(barcode);


+ 59
- 2
lib/src/types/barcode_format.dart Parādīt failu

@@ -56,7 +56,63 @@ extension BarcodeTypesExtension on BarcodeFormat {
return index;
}

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

String get formatName {
switch (this) {
@@ -111,7 +167,8 @@ extension BarcodeTypesExtension on BarcodeFormat {
case BarcodeFormat.upcEanExtension:
return 'UPC_EAN_EXTENSION';
break;
default:
return 'NOT_VALID';
}
return 'NOT_VALID';
}
}

Notiek ielāde…
Atcelt
Saglabāt