unify MacOS error codes for FlutterError(); fix barcode error forat and don't se…
…nd a FlutterError through the sink
Showing
2 changed files
with
17 additions
and
9 deletions
| @@ -14,7 +14,7 @@ struct MobileScannerErrorCodes { | @@ -14,7 +14,7 @@ struct MobileScannerErrorCodes { | ||
| 14 | // because it uses the error message from the undelying error. | 14 | // because it uses the error message from the undelying error. |
| 15 | static let BARCODE_ERROR = "MOBILE_SCANNER_BARCODE_ERROR" | 15 | static let BARCODE_ERROR = "MOBILE_SCANNER_BARCODE_ERROR" |
| 16 | // The error code 'CAMERA_ERROR' does not have an error message, | 16 | // The error code 'CAMERA_ERROR' does not have an error message, |
| 17 | - // because it uses the error message from the underlying error. | 17 | + // because it uses the error message from the underlying error. |
| 18 | static let CAMERA_ERROR = "MOBILE_SCANNER_CAMERA_ERROR" | 18 | static let CAMERA_ERROR = "MOBILE_SCANNER_CAMERA_ERROR" |
| 19 | static let NO_CAMERA_ERROR = "MOBILE_SCANNER_NO_CAMERA_ERROR" | 19 | static let NO_CAMERA_ERROR = "MOBILE_SCANNER_NO_CAMERA_ERROR" |
| 20 | static let NO_CAMERA_ERROR_MESSAGE = "No cameras available." | 20 | static let NO_CAMERA_ERROR_MESSAGE = "No cameras available." |
| @@ -131,7 +131,10 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -131,7 +131,10 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 131 | 131 | ||
| 132 | if error != nil { | 132 | if error != nil { |
| 133 | DispatchQueue.main.async { | 133 | DispatchQueue.main.async { |
| 134 | - self?.sink?(FlutterError(code: "MobileScanner", message: error?.localizedDescription, details: nil)) | 134 | + self?.sink?([ |
| 135 | + "name": MobileScannerErrorCodes.BARCODE_ERROR, | ||
| 136 | + "data": error?.localizedDescription, | ||
| 137 | + ]) | ||
| 135 | } | 138 | } |
| 136 | return | 139 | return |
| 137 | } | 140 | } |
| @@ -180,9 +183,12 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -180,9 +183,12 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 180 | } | 183 | } |
| 181 | 184 | ||
| 182 | try imageRequestHandler.perform([barcodeRequest]) | 185 | try imageRequestHandler.perform([barcodeRequest]) |
| 183 | - } catch let e { | 186 | + } catch let error { |
| 184 | DispatchQueue.main.async { | 187 | DispatchQueue.main.async { |
| 185 | - self?.sink?(FlutterError(code: "MobileScanner", message: e.localizedDescription, details: nil)) | 188 | + self?.sink?([ |
| 189 | + "name": MobileScannerErrorCodes.BARCODE_ERROR, | ||
| 190 | + "data": error.localizedDescription, | ||
| 191 | + ]) | ||
| 186 | } | 192 | } |
| 187 | } | 193 | } |
| 188 | } | 194 | } |
| @@ -262,8 +268,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -262,8 +268,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 262 | 268 | ||
| 263 | func start(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | 269 | func start(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { |
| 264 | if (device != nil || captureSession != nil) { | 270 | if (device != nil || captureSession != nil) { |
| 265 | - result(FlutterError(code: "MobileScanner", | ||
| 266 | - message: "Called start() while already started!", | 271 | + result(FlutterError(code: MobileScannerErrorCodes.ALREADY_STARTED_ERROR, |
| 272 | + message: MobileScannerErrorCodes.ALREADY_STARTED_ERROR_MESSAGE, | ||
| 267 | details: nil)) | 273 | details: nil)) |
| 268 | return | 274 | return |
| 269 | } | 275 | } |
| @@ -294,8 +300,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -294,8 +300,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 294 | } | 300 | } |
| 295 | 301 | ||
| 296 | if (device == nil) { | 302 | if (device == nil) { |
| 297 | - result(FlutterError(code: "MobileScanner", | ||
| 298 | - message: "No camera found or failed to open camera!", | 303 | + result(FlutterError(code: MobileScannerErrorCodes.NO_CAMERA_ERROR, |
| 304 | + message: MobileScannerErrorCodes.NO_CAMERA_ERROR_MESSAGE, | ||
| 299 | details: nil)) | 305 | details: nil)) |
| 300 | return | 306 | return |
| 301 | } | 307 | } |
| @@ -313,7 +319,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -313,7 +319,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 313 | let input = try AVCaptureDeviceInput(device: device) | 319 | let input = try AVCaptureDeviceInput(device: device) |
| 314 | captureSession!.addInput(input) | 320 | captureSession!.addInput(input) |
| 315 | } catch { | 321 | } catch { |
| 316 | - result(FlutterError(code: "MobileScanner", message: error.localizedDescription, details: nil)) | 322 | + result(FlutterError( |
| 323 | + code: MobileScannerErrorCodes.CAMERA_ERROR, | ||
| 324 | + message: error.localizedDescription, details: nil)) | ||
| 317 | return | 325 | return |
| 318 | } | 326 | } |
| 319 | captureSession!.sessionPreset = AVCaptureSession.Preset.photo | 327 | captureSession!.sessionPreset = AVCaptureSession.Preset.photo |
-
Please register or login to post a comment