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-09-28 11:19:24 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e9b3ad4796b4bbaae6678da83ba6364ea1d4ae28
e9b3ad47
1 parent
8bc967cf
handle barcode error events in the method channel implementation
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
lib/src/method_channel/mobile_scanner_method_channel.dart
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
e9b3ad4
...
...
@@ -44,22 +44,11 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
int
?
_textureId
;
/// Parse a [BarcodeCapture] from the given [event].
///
/// If the event name is [kBarcodeErrorEventName],
/// a [MobileScannerBarcodeException] is thrown.
BarcodeCapture
?
_parseBarcode
(
Map
<
Object
?,
Object
?>?
event
)
{
if
(
event
==
null
)
{
return
null
;
}
if
(
event
case
{
'name'
:
kBarcodeErrorEventName
,
'data'
:
final
String
?
errorDescription
})
{
throw
MobileScannerBarcodeException
(
errorDescription
);
}
final
Object
?
data
=
event
[
'data'
];
if
(
data
==
null
||
data
is
!
List
<
Object
?>)
{
...
...
@@ -94,6 +83,19 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
);
}
/// Parse a [MobileScannerBarcodeException] from the given [error] and [stackTrace], and throw it.
///
/// If the error is not a [PlatformException],
/// with [kBarcodeErrorEventName] as [PlatformException.code], the error is rethrown as-is.
Never
_parseBarcodeError
(
Object
error
,
StackTrace
stackTrace
)
{
if
(
error
case
PlatformException
(:
final
String
code
,
:
final
String
?
message
)
when
code
==
kBarcodeErrorEventName
)
{
throw
MobileScannerBarcodeException
(
message
);
}
Error
.
throwWithStackTrace
(
error
,
stackTrace
);
}
/// Request permission to access the camera.
///
/// Throws a [MobileScannerException] if the permission is not granted.
...
...
@@ -136,13 +138,12 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
@override
Stream
<
BarcodeCapture
?>
get
barcodesStream
{
// Handle both incoming barcode events and barcode error events.
return
eventsStream
.
where
(
(
event
)
{
return
event
[
'name'
]
==
'barcode'
||
event
[
'name'
]
==
kBarcodeErrorEventName
;
},
).
map
((
event
)
=>
_parseBarcode
(
event
));
// Handle incoming barcode events.
// The error events are transformed to `MobileScannerBarcodeException` where possible.
return
eventsStream
.
where
((
e
)
=>
e
[
'name'
]
==
'barcode'
)
.
map
((
event
)
=>
_parseBarcode
(
event
))
.
handleError
(
_parseBarcodeError
);
}
@override
...
...
Please
register
or
login
to post a comment