-
-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle errors in onDetect; exclude armv7 for iOS #1213
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added armv7 for both devices & simulators, per the MLKit docs. This should fix the reported build issue with IPA's. |
||
'EXCLUDED_ARCHS[sdk=iphoneos*]' => 'armv7', | ||
} | ||
s.swift_version = '5.0' | ||
s.resource_bundles = { 'mobile_scanner_privacy' => ['Resources/PrivacyInfo.xcprivacy'] } | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This guidance is obsolete, as we now can handle errors in the case. |
||
/// | ||
/// 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<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> | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were not handling errors from the stream when using on detect. |
||
cancelOnError: false, | ||
); | ||
} | ||
if (controller.autoStart) { | ||
controller.start(); | ||
|
@@ -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: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was badly indented