Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2024-10-11 08:55:17 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
89bda00ff240ea9e891ff3a8bda8ac7d2dcbd16c
89bda00f
1 parent
02e4c66e
handle errors with onDetect
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
lib/src/mobile_scanner.dart
lib/src/mobile_scanner.dart
View file @
89bda00
...
...
@@ -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
<
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
,
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
:
...
...
Please
register
or
login
to post a comment