Showing
1 changed file
with
19 additions
and
11 deletions
| @@ -37,24 +37,30 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -37,24 +37,30 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 37 | 37 | ||
| 38 | init(barcodeHandler: BarcodeHandler, registry: FlutterTextureRegistry) { | 38 | init(barcodeHandler: BarcodeHandler, registry: FlutterTextureRegistry) { |
| 39 | self.mobileScanner = MobileScanner(registry: registry, mobileScannerCallback: { barcodes, error, image in | 39 | self.mobileScanner = MobileScanner(registry: registry, mobileScannerCallback: { barcodes, error, image in |
| 40 | - if barcodes != nil { | 40 | + if error != nil { |
| 41 | + barcodeHandler.publishEvent(["name": "error", "data": error!.localizedDescription]) | ||
| 42 | + return | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + if barcodes == nil { | ||
| 46 | + return | ||
| 47 | + } | ||
| 48 | + | ||
| 41 | let barcodesMap: [Any?] = barcodes!.compactMap { barcode in | 49 | let barcodesMap: [Any?] = barcodes!.compactMap { barcode in |
| 42 | - if (MobileScannerPlugin.scanWindow != nil) { | ||
| 43 | - if (MobileScannerPlugin.isBarcodeInScanWindow(barcode: barcode, imageSize: image.size)) { | 50 | + if (MobileScannerPlugin.scanWindow == nil) { |
| 44 | return barcode.data | 51 | return barcode.data |
| 45 | - } else { | ||
| 46 | - return nil | ||
| 47 | } | 52 | } |
| 48 | - } else { | 53 | + |
| 54 | + if (MobileScannerPlugin.isBarcodeInScanWindow(barcode: barcode, imageSize: image.size)) { | ||
| 49 | return barcode.data | 55 | return barcode.data |
| 50 | } | 56 | } |
| 57 | + | ||
| 58 | + return nil | ||
| 51 | } | 59 | } |
| 60 | + | ||
| 52 | if (!barcodesMap.isEmpty) { | 61 | if (!barcodesMap.isEmpty) { |
| 53 | barcodeHandler.publishEvent(["name": "barcode", "data": barcodesMap, "image": FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!), "width": image.size.width, "height": image.size.height]) | 62 | barcodeHandler.publishEvent(["name": "barcode", "data": barcodesMap, "image": FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!), "width": image.size.width, "height": image.size.height]) |
| 54 | } | 63 | } |
| 55 | - } else if (error != nil){ | ||
| 56 | - barcodeHandler.publishEvent(["name": "error", "data": error!.localizedDescription]) | ||
| 57 | - } | ||
| 58 | }, torchModeChangeCallback: { torchState in | 64 | }, torchModeChangeCallback: { torchState in |
| 59 | barcodeHandler.publishEvent(["name": "torchState", "data": torchState]) | 65 | barcodeHandler.publishEvent(["name": "torchState", "data": torchState]) |
| 60 | }, zoomScaleChangeCallback: { zoomScale in | 66 | }, zoomScaleChangeCallback: { zoomScale in |
| @@ -257,13 +263,15 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -257,13 +263,15 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 257 | DispatchQueue.main.async { | 263 | DispatchQueue.main.async { |
| 258 | result(nil) | 264 | result(nil) |
| 259 | } | 265 | } |
| 260 | - } else { | 266 | + |
| 267 | + return | ||
| 268 | + } | ||
| 269 | + | ||
| 261 | let barcodesMap: [Any?] = barcodes!.compactMap { barcode in barcode.data } | 270 | let barcodesMap: [Any?] = barcodes!.compactMap { barcode in barcode.data } |
| 262 | 271 | ||
| 263 | DispatchQueue.main.async { | 272 | DispatchQueue.main.async { |
| 264 | result(["name": "barcode", "data": barcodesMap]) | 273 | result(["name": "barcode", "data": barcodesMap]) |
| 265 | } | 274 | } |
| 266 | - } | ||
| 267 | }) | 275 | }) |
| 268 | } | 276 | } |
| 269 | } | 277 | } |
-
Please register or login to post a comment