Skip to content

Commit

Permalink
Merge pull request #1213 from navaronbracke/onDetect_handle_error
Browse files Browse the repository at this point in the history
fix: handle errors in onDetect; exclude armv7 for iOS
  • Loading branch information
navaronbracke authored Oct 11, 2024
2 parents 02e4c66 + 79aea51 commit dcf46c2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:**
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions ios/mobile_scanner.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
30 changes: 23 additions & 7 deletions lib/src/mobile_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand Down Expand Up @@ -122,6 +125,11 @@ class MobileScanner extends StatefulWidget {

@override
State<MobileScanner> 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<MobileScanner>
Expand Down Expand Up @@ -255,7 +263,11 @@ class _MobileScannerState extends State<MobileScanner>
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();
Expand Down Expand Up @@ -297,7 +309,11 @@ class _MobileScannerState extends State<MobileScanner>
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:
Expand Down
2 changes: 1 addition & 1 deletion macos/mobile_scanner.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit dcf46c2

Please sign in to comment.