Navaron Bracke

use separate method to create scanner options on iOS

@@ -134,16 +134,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { @@ -134,16 +134,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
134 self.mobileScanner.timeoutSeconds = Double(timeoutMs) / Double(1000) 134 self.mobileScanner.timeoutSeconds = Double(timeoutMs) / Double(1000)
135 MobileScannerPlugin.returnImage = returnImage 135 MobileScannerPlugin.returnImage = returnImage
136 136
137 - let formatList = formats.map { format in return BarcodeFormat(rawValue: format)}  
138 - var barcodeOptions: BarcodeScannerOptions? = nil  
139 -  
140 - if (formatList.count != 0) {  
141 - var barcodeFormats: BarcodeFormat = []  
142 - for index in formats {  
143 - barcodeFormats.insert(BarcodeFormat(rawValue: index))  
144 - }  
145 - barcodeOptions = BarcodeScannerOptions(formats: barcodeFormats)  
146 - } 137 + let barcodeOptions: BarcodeScannerOptions? = buildBarcodeScannerOptions(formats)
147 138
148 let position = facing == 0 ? AVCaptureDevice.Position.front : .back 139 let position = facing == 0 ? AVCaptureDevice.Position.front : .back
149 let detectionSpeed: DetectionSpeed = DetectionSpeed(rawValue: speed)! 140 let detectionSpeed: DetectionSpeed = DetectionSpeed(rawValue: speed)!
@@ -297,4 +288,18 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { @@ -297,4 +288,18 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
297 } 288 }
298 }) 289 })
299 } 290 }
  291 +
  292 + private func buildBarcodeScannerOptions(_ formats: [Int]) -> BarcodeScannerOptions? {
  293 + guard !formats.isEmpty else {
  294 + return nil
  295 + }
  296 +
  297 + var barcodeFormats: BarcodeFormat = []
  298 +
  299 + for format in formats {
  300 + barcodeFormats.insert(BarcodeFormat(rawValue: format))
  301 + }
  302 +
  303 + return BarcodeScannerOptions(formats: barcodeFormats)
  304 + }
300 } 305 }