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-06-18 09:47:17 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
518081220c3e317dbde4619327e163bea42d839a
51808122
1 parent
43e6cb59
emit barcode errors through the channel
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
lib/src/method_channel/mobile_scanner_method_channel.dart
lib/src/mobile_scanner_controller.dart
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
5180812
...
...
@@ -16,6 +16,10 @@ import 'package:mobile_scanner/src/objects/start_options.dart';
/// An implementation of [MobileScannerPlatform] that uses method channels.
class
MethodChannelMobileScanner
extends
MobileScannerPlatform
{
/// The name of the error event that is sent when a barcode scan error occurs.
@visibleForTesting
static
const
String
kBarcodeErrorEventName
=
'MOBILE_SCANNER_BARCODE_ERROR'
;
/// The method channel used to interact with the native platform.
@visibleForTesting
final
methodChannel
=
const
MethodChannel
(
...
...
@@ -40,11 +44,22 @@ 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
?>)
{
...
...
@@ -121,9 +136,13 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
@override
Stream
<
BarcodeCapture
?>
get
barcodesStream
{
return
eventsStream
.
where
((
event
)
=>
event
[
'name'
]
==
'barcode'
)
.
map
((
event
)
=>
_parseBarcode
(
event
));
// Handle both incoming barcode events and barcode error events.
return
eventsStream
.
where
(
(
event
)
{
return
event
[
'name'
]
==
'barcode'
||
event
[
'name'
]
==
kBarcodeErrorEventName
;
},
).
map
((
event
)
=>
_parseBarcode
(
event
));
}
@override
...
...
lib/src/mobile_scanner_controller.dart
View file @
5180812
...
...
@@ -102,6 +102,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
StreamController
.
broadcast
();
/// Get the stream of scanned barcodes.
///
/// If an error occurred during the detection of a barcode,
/// an [MobileScannerBarcodeException] error is emitted to the stream.
Stream
<
BarcodeCapture
>
get
barcodes
=>
_barcodesController
.
stream
;
StreamSubscription
<
BarcodeCapture
?>?
_barcodesSubscription
;
...
...
Please
register
or
login
to post a comment