diff --git a/CHANGELOG.md b/CHANGELOG.md index 6064cbbae..128e29fd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 6.0.1 + +Bugs fixed: +* Fixed a bug that would cause onDetect to not handle errors. + +Improvements: +* [iOS] Excluded the `armv7` architecture, which is unsupported by MLKit 7.0.0. +* Added a new `onDetectError` error handler to the `MobileScanner` widget, for use with `onDetect`. + ## 6.0.0 **BREAKING CHANGES:** diff --git a/example/ios/Podfile b/example/ios/Podfile index 5226bfe73..d9ee07199 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -40,8 +40,8 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) - target.build_configurations.each do |config| - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5.0' - end + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5.0' + end end end diff --git a/ios/mobile_scanner.podspec b/ios/mobile_scanner.podspec index 74fc05420..832f6c652 100644 --- a/ios/mobile_scanner.podspec +++ b/ios/mobile_scanner.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'mobile_scanner' - s.version = '6.0.0' + s.version = '6.0.1' s.summary = 'An universal scanner for Flutter based on MLKit.' s.description = <<-DESC An universal scanner for Flutter based on MLKit. @@ -18,8 +18,12 @@ An universal scanner for Flutter based on MLKit. s.dependency 'GoogleMLKit/BarcodeScanning', '~> 7.0.0' s.platform = :ios, '15.5.0' s.static_framework = true - # Flutter.framework does not contain a i386 slice. - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } + # Flutter.framework does not contain a i386 slice, and MLKit does not support armv7. + s.pod_target_xcconfig = { + 'DEFINES_MODULE' => 'YES', + 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386 armv7', + 'EXCLUDED_ARCHS[sdk=iphoneos*]' => 'armv7', + } s.swift_version = '5.0' s.resource_bundles = { 'mobile_scanner_privacy' => ['Resources/PrivacyInfo.xcprivacy'] } end diff --git a/lib/src/mobile_scanner.dart b/lib/src/mobile_scanner.dart index ef4663d3a..3f1163554 100644 --- a/lib/src/mobile_scanner.dart +++ b/lib/src/mobile_scanner.dart @@ -21,6 +21,7 @@ class MobileScanner extends StatefulWidget { const MobileScanner({ this.controller, this.onDetect, + this.onDetectError = _onDetectErrorHandler, this.fit = BoxFit.cover, this.errorBuilder, this.overlayBuilder, @@ -34,15 +35,17 @@ class MobileScanner extends StatefulWidget { final MobileScannerController? controller; /// The function that signals when new codes were detected by the [controller]. - /// If null, use the controller.barcodes stream directly to capture barcodes. - /// - /// This method does not receive any [MobileScannerBarcodeException]s - /// that are emitted by the scanner. /// /// To handle both [BarcodeCapture]s and [MobileScannerBarcodeException]s, - /// use the [MobileScannerController.barcodes] stream directly. + /// use the [MobileScannerController.barcodes] stream directly (recommended), + /// or provide a function to [onDetectError]. final void Function(BarcodeCapture barcodes)? onDetect; + /// The error handler equivalent for the [onDetect] function. + /// + /// If [onDetect] is not null, and this is null, errors are silently ignored. + final void Function(Object error, StackTrace stackTrace) onDetectError; + /// The error builder for the camera preview. /// /// If this is null, a black [ColoredBox], @@ -122,6 +125,11 @@ class MobileScanner extends StatefulWidget { @override State createState() => _MobileScannerState(); + + /// This empty function is used as the default error handler for [onDetect]. + static void _onDetectErrorHandler(Object error, StackTrace stackTrace) { + // Do nothing. + } } class _MobileScannerState extends State @@ -255,7 +263,11 @@ class _MobileScannerState extends State void initState() { if (widget.onDetect != null) { WidgetsBinding.instance.addObserver(this); - _subscription = controller.barcodes.listen(widget.onDetect); + _subscription = controller.barcodes.listen( + widget.onDetect, + onError: widget.onDetectError, + cancelOnError: false, + ); } if (controller.autoStart) { controller.start(); @@ -297,7 +309,11 @@ class _MobileScannerState extends State case AppLifecycleState.paused: return; case AppLifecycleState.resumed: - _subscription = controller.barcodes.listen(widget.onDetect); + _subscription = controller.barcodes.listen( + widget.onDetect, + onError: widget.onDetectError, + cancelOnError: false, + ); unawaited(controller.start()); case AppLifecycleState.inactive: diff --git a/macos/mobile_scanner.podspec b/macos/mobile_scanner.podspec index 44174bc42..2fbf0360e 100644 --- a/macos/mobile_scanner.podspec +++ b/macos/mobile_scanner.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'mobile_scanner' - s.version = '6.0.0' + s.version = '6.0.1' s.summary = 'An universal scanner for Flutter based on MLKit.' s.description = <<-DESC An universal scanner for Flutter based on MLKit. diff --git a/pubspec.yaml b/pubspec.yaml index 83542032d..1255535e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mobile_scanner 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. -version: 6.0.0 +version: 6.0.1 repository: https://github.com/juliansteenbakker/mobile_scanner screenshots: