Added raw-bytes support for iOSflutter-beta
| @@ -162,8 +162,33 @@ public class QRView:NSObject,FlutterPlatformView { | |||||
| default: | default: | ||||
| return | 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) { | if allowedBarcodeTypes.count == 0 || allowedBarcodeTypes.contains(code.type) { | ||||
| self?.channel.invokeMethod("onRecognizeQR", arguments: result) | self?.channel.invokeMethod("onRecognizeQR", arguments: result) | ||||
| } | } | ||||
| @@ -187,7 +187,7 @@ 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 code = args['code'] as String?; | |||||
| 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>?; | ||||
| @@ -2,15 +2,15 @@ import 'barcode_format.dart'; | |||||
| /// The [Barcode] object holds information about the barcode or qr code. | /// 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. | /// [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 { | class Barcode { | ||||
| Barcode(this.code, this.format, this.rawBytes); | Barcode(this.code, this.format, this.rawBytes); | ||||
| final String code; | |||||
| final String? code; | |||||
| final BarcodeFormat format; | final BarcodeFormat format; | ||||
| /// Raw bytes are only supported by Android. | |||||
| /// Raw bytes are only supported by Android and iOS. | |||||
| final List<int>? rawBytes; | final List<int>? rawBytes; | ||||
| } | } | ||||