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 10:58:32 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8bc967cf6a18f3587f59aa8775c02ccf9b185db8
8bc967cf
1 parent
eda540fd
forward errors from ZXing
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
lib/src/web/mobile_scanner_web.dart
lib/src/web/zxing/zxing_barcode_reader.dart
lib/src/web/zxing/zxing_exception.dart
lib/src/web/mobile_scanner_web.dart
View file @
8bc967c
...
...
@@ -322,6 +322,15 @@ class MobileScannerWeb extends MobileScannerPlatform {
_barcodesController
.
add
(
barcode
);
},
onError:
(
Object
error
)
{
if
(
_barcodesController
.
isClosed
)
{
return
;
}
_barcodesController
.
addError
(
error
);
},
// Errors are handled gracefully by forwarding them.
cancelOnError:
false
,
);
final
bool
hasTorch
=
await
_barcodeReader
?.
hasTorch
()
??
false
;
...
...
lib/src/web/zxing/zxing_barcode_reader.dart
View file @
8bc967c
...
...
@@ -3,6 +3,7 @@ import 'dart:js_interop';
import
'dart:ui'
;
import
'package:mobile_scanner/src/enums/barcode_format.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_exception.dart'
;
import
'package:mobile_scanner/src/objects/barcode_capture.dart'
;
import
'package:mobile_scanner/src/objects/start_options.dart'
;
import
'package:mobile_scanner/src/web/barcode_reader.dart'
;
...
...
@@ -10,6 +11,7 @@ import 'package:mobile_scanner/src/web/javascript_map.dart';
import
'package:mobile_scanner/src/web/media_track_constraints_delegate.dart'
;
import
'package:mobile_scanner/src/web/zxing/result.dart'
;
import
'package:mobile_scanner/src/web/zxing/zxing_browser_multi_format_reader.dart'
;
import
'package:mobile_scanner/src/web/zxing/zxing_exception.dart'
;
import
'package:web/web.dart'
as
web
;
/// A barcode reader implementation that uses the ZXing library.
...
...
@@ -98,16 +100,23 @@ final class ZXingBarcodeReader extends BarcodeReader {
_reader
?.
decodeContinuously
.
callAsFunction
(
_reader
,
_reader
?.
videoElement
,
(
Result
?
result
,
JSAny
?
error
)
{
if
(
controller
.
isClosed
||
result
==
null
)
{
(
Result
?
result
,
ZXingException
?
error
)
{
if
(
controller
.
isClosed
)
{
return
;
}
if
(
error
!=
null
)
{
controller
.
addError
(
MobileScannerBarcodeException
(
error
.
message
));
return
;
}
if
(
result
!=
null
)
{
controller
.
add
(
BarcodeCapture
(
barcodes:
[
result
.
toBarcode
],
),
);
}
}.
toJS
,
);
};
...
...
lib/src/web/zxing/zxing_exception.dart
0 → 100644
View file @
8bc967c
import
'dart:js_interop'
;
/// The JS static interop class for the Result class in the ZXing library.
///
/// See also: https://github.com/zxing-js/library/blob/master/src/core/Exception.ts
@JS
(
'ZXing.Exception'
)
extension
type
ZXingException
.
_
(
JSObject
_
)
implements
JSObject
{
/// The error message of the exception, if any.
external
String
?
get
message
;
}
...
...
Please
register
or
login
to post a comment