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

Added documentation.

Added string to barcode format function.
flutter-beta
Julian Steenbakker 5 лет назад
Родитель
Сommit
5a3771a508
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 16E437C7A3D94250
2 измененных файлов: 77 добавлений и 24 удалений
  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 Просмотреть файл

@@ -14,7 +14,8 @@ import 'types/features.dart';
typedef QRViewCreatedCallback = void Function(QRViewController); typedef QRViewCreatedCallback = void Function(QRViewController);
typedef PermissionSetCallback = void Function(QRViewController, bool); 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 { class QRView extends StatefulWidget {
const QRView({ const QRView({
@required Key key, @required Key key,
@@ -28,11 +29,26 @@ class QRView extends StatefulWidget {
assert(onQRViewCreated != null), assert(onQRViewCreated != null),
super(key: key); super(key: key);


/// [onQRViewCreated] gets called when the view is created
final QRViewCreatedCallback onQRViewCreated; 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; final ShapeBorder overlay;

/// Use [overlayMargin] to provide a margin to [overlay]
final EdgeInsetsGeometry overlayMargin; 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; final CameraFacing cameraFacing;

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

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


@override @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 { class QRViewController {
QRViewController._( QRViewController._(
MethodChannel channel, MethodChannel channel,
@@ -178,7 +174,7 @@ class QRViewController {
final rawType = args['type'] 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 = _formatNames[rawType];
final format = BarcodeTypesExtension.fromString(rawType);
if (format != null) { if (format != null) {
final barcode = Barcode(code, format, rawBytes); final barcode = Barcode(code, format, rawBytes);
_scanUpdateController.sink.add(barcode); _scanUpdateController.sink.add(barcode);


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

@@ -56,7 +56,63 @@ extension BarcodeTypesExtension on BarcodeFormat {
return index; 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 { String get formatName {
switch (this) { switch (this) {
@@ -111,7 +167,8 @@ extension BarcodeTypesExtension on BarcodeFormat {
case BarcodeFormat.upcEanExtension: case BarcodeFormat.upcEanExtension:
return 'UPC_EAN_EXTENSION'; return 'UPC_EAN_EXTENSION';
break; break;
default:
return 'NOT_VALID';
} }
return 'NOT_VALID';
} }
} }

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