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-01-03 17:11:05 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6c46a25f449277a3bbb3e6c6f71cac327afb05a2
6c46a25f
1 parent
f47d16e6
fix compilation error on web; don't depend on package:js anymore for dart2wasm
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
52 deletions
lib/src/web/barcode_reader.dart
lib/src/web/zxing/result.dart
lib/src/web/zxing/result_point.dart
lib/src/web/zxing/zxing_barcode_reader.dart
pubspec.yaml
lib/src/web/barcode_reader.dart
View file @
6c46a25
import
'dart:async'
;
import
'dart:js'
;
import
'dart:js_interop'
;
import
'dart:ui'
;
import
'package:js/js.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'
;
import
'package:mobile_scanner/src/enums/torch_state.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_exception.dart'
;
...
...
lib/src/web/zxing/result.dart
View file @
6c46a25
...
...
@@ -11,32 +11,31 @@ import 'package:mobile_scanner/src/web/zxing/result_point.dart';
///
/// See also: https://github.com/zxing-js/library/blob/master/src/core/Result.ts
@JS
()
@anonymous
@staticInterop
abstract
class
Result
{}
extension
ResultExt
on
Result
{
/// Get the barcode format.
///
/// See also https://github.com/zxing-js/library/blob/master/src/core/BarcodeFormat.ts
external
JSFunction
getBarcodeFormat
;
@JS
(
'barcodeFormat'
)
external
JSNumber
?
get
_barcodeFormat
;
/// Get the raw bytes of the result.
external
JSFunction
getRawBytes
;
@JS
(
'text'
)
external
JSString
?
get
_text
;
/// Get the points of the result.
external
JSFunction
getResultPoints
;
@JS
(
'rawBytes'
)
external
JSUint8Array
?
get
_rawBytes
;
/// Get the text of the result.
external
JSFunction
getText
;
@JS
(
'resultPoints'
)
external
JSArray
?
get
_resultPoints
;
/// Get the timestamp of the result.
external
JSFunction
getTimestamp
;
@JS
(
'timestamp'
)
external
JSNumber
?
get
_timestamp
;
/// Get the barcode format of the result.
///
/// See also https://github.com/zxing-js/library/blob/master/src/core/BarcodeFormat.ts
BarcodeFormat
get
barcodeFormat
{
final
JSNumber
?
format
=
getBarcodeFormat
.
callAsFunction
()
as
JSNumber
?;
switch
(
format
?.
toDartInt
)
{
switch
(
_barcodeFormat
?.
toDartInt
)
{
case
0
:
return
BarcodeFormat
.
aztec
;
case
1
:
...
...
@@ -82,36 +81,25 @@ extension ResultExt on Result {
/// Get the corner points of the result.
List
<
Offset
>
get
resultPoints
{
final
JSArray
?
resultPoints
=
getResultPoints
.
callAsFunction
()
as
JSArray
?
;
final
JSArray
?
points
=
_resultPoints
;
if
(
resultP
oints
==
null
)
{
if
(
p
oints
==
null
)
{
return
[];
}
return
resultP
oints
.
toDart
.
cast
<
ResultPoint
>().
map
((
point
)
{
return
p
oints
.
toDart
.
cast
<
ResultPoint
>().
map
((
point
)
{
return
Offset
(
point
.
x
,
point
.
y
);
}).
toList
();
}
/// Get the raw bytes of the result.
Uint8List
?
get
rawBytes
{
final
JSUint8Array
?
rawBytes
=
getRawBytes
.
callAsFunction
()
as
JSUint8Array
?;
return
rawBytes
?.
toDart
;
}
Uint8List
?
get
rawBytes
=>
_rawBytes
?.
toDart
;
/// Get the text of the result.
String
?
get
text
{
return
getText
.
callAsFunction
()
as
String
?;
}
String
?
get
text
=>
_text
?.
toDart
;
/// Get the timestamp of the result.
int
?
get
timestamp
{
final
JSNumber
?
timestamp
=
getTimestamp
.
callAsFunction
()
as
JSNumber
?;
return
timestamp
?.
toDartInt
;
}
int
?
get
timestamp
=>
_timestamp
?.
toDartInt
;
/// Convert this result to a [Barcode].
Barcode
get
toBarcode
{
...
...
lib/src/web/zxing/result_point.dart
View file @
6c46a25
...
...
@@ -4,25 +4,20 @@ import 'dart:js_interop';
///
/// See also: https://github.com/zxing-js/library/blob/master/src/core/ResultPoint.ts
@JS
()
@anonymous
@staticInterop
abstract
class
ResultPoint
{}
extension
ResultPointExt
on
ResultPoint
{
external
JSFunction
getX
;
@JS
(
'x'
)
external
JSNumber
get
_x
;
external
JSFunction
getY
;
@JS
(
'y'
)
external
JSNumber
get
_y
;
/// The x coordinate of the point.
double
get
x
{
final
JSNumber
?
x
=
getX
.
callAsFunction
()
as
JSNumber
?;
return
x
?.
toDartDouble
??
0
;
}
double
get
x
=>
_x
.
toDartDouble
;
/// The y coordinate of the point.
double
get
y
{
final
JSNumber
?
y
=
getY
.
callAsFunction
()
as
JSNumber
?;
return
y
?.
toDartDouble
??
0
;
}
double
get
y
=>
_y
.
toDartDouble
;
}
...
...
lib/src/web/zxing/zxing_barcode_reader.dart
View file @
6c46a25
import
'dart:async'
;
import
'dart:js'
;
import
'dart:js_interop'
;
import
'dart:ui'
;
import
'package:js/js.dart'
;
import
'package:mobile_scanner/src/enums/barcode_format.dart'
;
import
'package:mobile_scanner/src/enums/camera_facing.dart'
;
import
'package:mobile_scanner/src/enums/torch_state.dart'
;
...
...
@@ -161,13 +161,11 @@ final class ZXingBarcodeReader extends BarcodeReader {
_reader
?.
decodeContinuously
.
callAsFunction
(
null
,
_reader
?.
videoElement
,
allowInterop
((
result
,
error
)
{
allowInterop
((
Result
?
result
,
JSAny
?
error
)
{
if
(!
controller
.
isClosed
&&
result
!=
null
)
{
final
barcode
=
(
result
as
Result
).
toBarcode
;
controller
.
add
(
BarcodeCapture
(
barcodes:
[
b
arcode
],
barcodes:
[
result
.
toB
arcode
],
),
);
}
...
...
pubspec.yaml
View file @
6c46a25
...
...
@@ -24,7 +24,6 @@ dependencies:
sdk
:
flutter
flutter_web_plugins
:
sdk
:
flutter
js
:
^0.6.3
plugin_platform_interface
:
^2.0.2
web
:
^0.3.0
...
...
@@ -45,4 +44,4 @@ flutter:
pluginClass
:
MobileScannerPlugin
web
:
pluginClass
:
MobileScannerWeb
fileName
:
web/mobile_scanner_web.dart
fileName
:
src/
web/mobile_scanner_web.dart
...
...
Please
register
or
login
to post a comment