Committed by
GitHub
Merge pull request #1213 from navaronbracke/onDetect_handle_error
fix: handle errors in onDetect; exclude armv7 for iOS
Showing
6 changed files
with
41 additions
and
12 deletions
| 1 | +## 6.0.1 | ||
| 2 | + | ||
| 3 | +Bugs fixed: | ||
| 4 | +* Fixed a bug that would cause onDetect to not handle errors. | ||
| 5 | + | ||
| 6 | +Improvements: | ||
| 7 | +* [iOS] Excluded the `armv7` architecture, which is unsupported by MLKit 7.0.0. | ||
| 8 | +* Added a new `onDetectError` error handler to the `MobileScanner` widget, for use with `onDetect`. | ||
| 9 | + | ||
| 1 | ## 6.0.0 | 10 | ## 6.0.0 |
| 2 | 11 | ||
| 3 | **BREAKING CHANGES:** | 12 | **BREAKING CHANGES:** |
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | # | 4 | # |
| 5 | Pod::Spec.new do |s| | 5 | Pod::Spec.new do |s| |
| 6 | s.name = 'mobile_scanner' | 6 | s.name = 'mobile_scanner' |
| 7 | - s.version = '6.0.0' | 7 | + s.version = '6.0.1' |
| 8 | s.summary = 'An universal scanner for Flutter based on MLKit.' | 8 | s.summary = 'An universal scanner for Flutter based on MLKit.' |
| 9 | s.description = <<-DESC | 9 | s.description = <<-DESC |
| 10 | An universal scanner for Flutter based on MLKit. | 10 | An universal scanner for Flutter based on MLKit. |
| @@ -18,8 +18,12 @@ An universal scanner for Flutter based on MLKit. | @@ -18,8 +18,12 @@ An universal scanner for Flutter based on MLKit. | ||
| 18 | s.dependency 'GoogleMLKit/BarcodeScanning', '~> 7.0.0' | 18 | s.dependency 'GoogleMLKit/BarcodeScanning', '~> 7.0.0' |
| 19 | s.platform = :ios, '15.5.0' | 19 | s.platform = :ios, '15.5.0' |
| 20 | s.static_framework = true | 20 | s.static_framework = true |
| 21 | - # Flutter.framework does not contain a i386 slice. | ||
| 22 | - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } | 21 | + # Flutter.framework does not contain a i386 slice, and MLKit does not support armv7. |
| 22 | + s.pod_target_xcconfig = { | ||
| 23 | + 'DEFINES_MODULE' => 'YES', | ||
| 24 | + 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386 armv7', | ||
| 25 | + 'EXCLUDED_ARCHS[sdk=iphoneos*]' => 'armv7', | ||
| 26 | + } | ||
| 23 | s.swift_version = '5.0' | 27 | s.swift_version = '5.0' |
| 24 | s.resource_bundles = { 'mobile_scanner_privacy' => ['Resources/PrivacyInfo.xcprivacy'] } | 28 | s.resource_bundles = { 'mobile_scanner_privacy' => ['Resources/PrivacyInfo.xcprivacy'] } |
| 25 | end | 29 | end |
| @@ -21,6 +21,7 @@ class MobileScanner extends StatefulWidget { | @@ -21,6 +21,7 @@ class MobileScanner extends StatefulWidget { | ||
| 21 | const MobileScanner({ | 21 | const MobileScanner({ |
| 22 | this.controller, | 22 | this.controller, |
| 23 | this.onDetect, | 23 | this.onDetect, |
| 24 | + this.onDetectError = _onDetectErrorHandler, | ||
| 24 | this.fit = BoxFit.cover, | 25 | this.fit = BoxFit.cover, |
| 25 | this.errorBuilder, | 26 | this.errorBuilder, |
| 26 | this.overlayBuilder, | 27 | this.overlayBuilder, |
| @@ -34,15 +35,17 @@ class MobileScanner extends StatefulWidget { | @@ -34,15 +35,17 @@ class MobileScanner extends StatefulWidget { | ||
| 34 | final MobileScannerController? controller; | 35 | final MobileScannerController? controller; |
| 35 | 36 | ||
| 36 | /// The function that signals when new codes were detected by the [controller]. | 37 | /// The function that signals when new codes were detected by the [controller]. |
| 37 | - /// If null, use the controller.barcodes stream directly to capture barcodes. | ||
| 38 | - /// | ||
| 39 | - /// This method does not receive any [MobileScannerBarcodeException]s | ||
| 40 | - /// that are emitted by the scanner. | ||
| 41 | /// | 38 | /// |
| 42 | /// To handle both [BarcodeCapture]s and [MobileScannerBarcodeException]s, | 39 | /// To handle both [BarcodeCapture]s and [MobileScannerBarcodeException]s, |
| 43 | - /// use the [MobileScannerController.barcodes] stream directly. | 40 | + /// use the [MobileScannerController.barcodes] stream directly (recommended), |
| 41 | + /// or provide a function to [onDetectError]. | ||
| 44 | final void Function(BarcodeCapture barcodes)? onDetect; | 42 | final void Function(BarcodeCapture barcodes)? onDetect; |
| 45 | 43 | ||
| 44 | + /// The error handler equivalent for the [onDetect] function. | ||
| 45 | + /// | ||
| 46 | + /// If [onDetect] is not null, and this is null, errors are silently ignored. | ||
| 47 | + final void Function(Object error, StackTrace stackTrace) onDetectError; | ||
| 48 | + | ||
| 46 | /// The error builder for the camera preview. | 49 | /// The error builder for the camera preview. |
| 47 | /// | 50 | /// |
| 48 | /// If this is null, a black [ColoredBox], | 51 | /// If this is null, a black [ColoredBox], |
| @@ -122,6 +125,11 @@ class MobileScanner extends StatefulWidget { | @@ -122,6 +125,11 @@ class MobileScanner extends StatefulWidget { | ||
| 122 | 125 | ||
| 123 | @override | 126 | @override |
| 124 | State<MobileScanner> createState() => _MobileScannerState(); | 127 | State<MobileScanner> createState() => _MobileScannerState(); |
| 128 | + | ||
| 129 | + /// This empty function is used as the default error handler for [onDetect]. | ||
| 130 | + static void _onDetectErrorHandler(Object error, StackTrace stackTrace) { | ||
| 131 | + // Do nothing. | ||
| 132 | + } | ||
| 125 | } | 133 | } |
| 126 | 134 | ||
| 127 | class _MobileScannerState extends State<MobileScanner> | 135 | class _MobileScannerState extends State<MobileScanner> |
| @@ -255,7 +263,11 @@ class _MobileScannerState extends State<MobileScanner> | @@ -255,7 +263,11 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 255 | void initState() { | 263 | void initState() { |
| 256 | if (widget.onDetect != null) { | 264 | if (widget.onDetect != null) { |
| 257 | WidgetsBinding.instance.addObserver(this); | 265 | WidgetsBinding.instance.addObserver(this); |
| 258 | - _subscription = controller.barcodes.listen(widget.onDetect); | 266 | + _subscription = controller.barcodes.listen( |
| 267 | + widget.onDetect, | ||
| 268 | + onError: widget.onDetectError, | ||
| 269 | + cancelOnError: false, | ||
| 270 | + ); | ||
| 259 | } | 271 | } |
| 260 | if (controller.autoStart) { | 272 | if (controller.autoStart) { |
| 261 | controller.start(); | 273 | controller.start(); |
| @@ -297,7 +309,11 @@ class _MobileScannerState extends State<MobileScanner> | @@ -297,7 +309,11 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 297 | case AppLifecycleState.paused: | 309 | case AppLifecycleState.paused: |
| 298 | return; | 310 | return; |
| 299 | case AppLifecycleState.resumed: | 311 | case AppLifecycleState.resumed: |
| 300 | - _subscription = controller.barcodes.listen(widget.onDetect); | 312 | + _subscription = controller.barcodes.listen( |
| 313 | + widget.onDetect, | ||
| 314 | + onError: widget.onDetectError, | ||
| 315 | + cancelOnError: false, | ||
| 316 | + ); | ||
| 301 | 317 | ||
| 302 | unawaited(controller.start()); | 318 | unawaited(controller.start()); |
| 303 | case AppLifecycleState.inactive: | 319 | case AppLifecycleState.inactive: |
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | # | 4 | # |
| 5 | Pod::Spec.new do |s| | 5 | Pod::Spec.new do |s| |
| 6 | s.name = 'mobile_scanner' | 6 | s.name = 'mobile_scanner' |
| 7 | - s.version = '6.0.0' | 7 | + s.version = '6.0.1' |
| 8 | s.summary = 'An universal scanner for Flutter based on MLKit.' | 8 | s.summary = 'An universal scanner for Flutter based on MLKit.' |
| 9 | s.description = <<-DESC | 9 | s.description = <<-DESC |
| 10 | An universal scanner for Flutter based on MLKit. | 10 | An universal scanner for Flutter based on MLKit. |
| 1 | name: mobile_scanner | 1 | name: mobile_scanner |
| 2 | description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS. | 2 | description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS. |
| 3 | -version: 6.0.0 | 3 | +version: 6.0.1 |
| 4 | repository: https://github.com/juliansteenbakker/mobile_scanner | 4 | repository: https://github.com/juliansteenbakker/mobile_scanner |
| 5 | 5 | ||
| 6 | screenshots: | 6 | screenshots: |
-
Please register or login to post a comment