Explorar el Código

Merge pull request #421 from joke1st/feature/raw_bytes_ios

Added raw-bytes support for iOS
flutter-beta
Julian Steenbakker hace 4 años
committed by GitHub
padre
commit
5d93d4a84d
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 3 ficheros con 32 adiciones y 7 borrados
  1. +27
    -2
      ios/Classes/QRView.swift
  2. +1
    -1
      lib/src/qr_code_scanner.dart
  3. +4
    -4
      lib/src/types/barcode.dart

+ 27
- 2
ios/Classes/QRView.swift Ver fichero

@@ -162,8 +162,33 @@ public class QRView:NSObject,FlutterPlatformView {
default:
return
}
guard let stringValue = code.stringValue else { continue }
let result = ["code": stringValue, "type": typeString]
let bytes = { () -> Data? in
switch (code.descriptor) {
case let qrDescriptor as CIQRCodeDescriptor:
return qrDescriptor.errorCorrectedPayload
case let aztecDescriptor as CIAztecCodeDescriptor:
return aztecDescriptor.errorCorrectedPayload
case let pdf417Descriptor as CIPDF417CodeDescriptor:
return pdf417Descriptor.errorCorrectedPayload
case let dataMatrixDescriptor as CIDataMatrixCodeDescriptor:
return dataMatrixDescriptor.errorCorrectedPayload
default:
return nil
}
}()
let result = { () -> [String : Any]? in
guard let stringValue = code.stringValue else {
guard let safeBytes = bytes else {
return nil
}
return ["type": typeString, "rawBytes": safeBytes]
}
guard let safeBytes = bytes else {
return ["code": stringValue, "type": typeString]
}
return ["code": stringValue, "type": typeString, "rawBytes": safeBytes]
}()
guard let safeResult = result else { continue }
if allowedBarcodeTypes.count == 0 || allowedBarcodeTypes.contains(code.type) {
self?.channel.invokeMethod("onRecognizeQR", arguments: result)
}


+ 1
- 1
lib/src/qr_code_scanner.dart Ver fichero

@@ -187,7 +187,7 @@ class QRViewController {
case 'onRecognizeQR':
if (call.arguments != null) {
final args = call.arguments as Map;
final code = args['code'] 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>?;


+ 4
- 4
lib/src/types/barcode.dart Ver fichero

@@ -2,15 +2,15 @@ import 'barcode_format.dart';

/// The [Barcode] object holds information about the barcode or qr code.
///
/// [code] is the content of the barcode.
/// [code] is the string-content of the barcode.
/// [format] displays which type the code is.
/// Only for Android, [rawBytes] gives a list of bytes of the result.
/// Only for Android and iOS, [rawBytes] gives a list of bytes of the result.
class Barcode {
Barcode(this.code, this.format, this.rawBytes);

final String code;
final String? code;
final BarcodeFormat format;

/// Raw bytes are only supported by Android.
/// Raw bytes are only supported by Android and iOS.
final List<int>? rawBytes;
}

Cargando…
Cancelar
Guardar