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
Koji Wakamiya
2024-03-09 11:35:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Navaron Bracke
2024-04-16 15:23:58 +0200
Commit
f31b03dcfb46ff4610f9c4941fe1d266a44cf200
f31b03dc
1 parent
fde4fc12
feat: Update extension type
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
87 deletions
lib/src/web/javascript_map.dart
lib/src/web/zxing/result.dart
lib/src/web/zxing/result_point.dart
lib/src/web/zxing/zxing_barcode_reader.dart
lib/src/web/zxing/zxing_browser_multi_format_reader.dart
lib/src/web/javascript_map.dart
View file @
f31b03d
...
...
@@ -9,12 +9,10 @@ import 'dart:js_interop';
///
/// Object literals can be made using [jsify].
@JS
(
'Map'
)
@staticInterop
class
JSMap
<
K
extends
JSAny
,
V
extends
JSAny
>
{
extension
type
JSMap
<
K
extends
JSAny
,
V
extends
JSAny
>.
_
(
JSObject
_
)
implements
JSObject
{
external
factory
JSMap
();
}
extension
JSMapExtension
<
K
extends
JSAny
,
V
extends
JSAny
>
on
JSMap
<
K
,
V
>
{
external
V
?
get
(
K
key
);
external
JSVoid
set
(
K
key
,
V
?
value
);
}
...
...
lib/src/web/zxing/result.dart
View file @
f31b03d
...
...
@@ -10,32 +10,27 @@ import 'package:mobile_scanner/src/web/zxing/result_point.dart';
/// 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/Result.ts
@JS
()
@anonymous
@staticInterop
abstract
class
Result
{}
extension
ResultExt
on
Result
{
extension
type
Result
(
JSObject
_
)
implements
JSObject
{
@JS
(
'barcodeFormat'
)
external
JSNumber
?
get
_barcodeFormat
;
external
int
?
get
_barcodeFormat
;
@JS
(
'text'
)
external
JSString
?
get
_text
;
/// Get the text of the result.
external
String
?
get
text
;
@JS
(
'rawBytes'
)
external
JSUint8Array
?
get
_rawBytes
;
@JS
(
'resultPoints'
)
external
JSArray
?
get
_resultPoints
;
external
JSArray
<
ResultPoint
>
?
get
_resultPoints
;
@JS
(
'timestamp'
)
external
JSNumber
?
get
_timestamp
;
/// Get the timestamp of the result.
external
int
?
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
{
switch
(
_barcodeFormat
?.
toDartInt
)
{
switch
(
_barcodeFormat
)
{
case
0
:
return
BarcodeFormat
.
aztec
;
case
1
:
...
...
@@ -79,28 +74,22 @@ extension ResultExt on Result {
}
}
/// Get the raw bytes of the result.
Uint8List
?
get
rawBytes
=>
_rawBytes
?.
toDart
;
/// Get the corner points of the result.
List
<
Offset
>
get
resultPoints
{
final
JSArray
?
points
=
_resultPoints
;
final
JSArray
<
ResultPoint
>
?
points
=
_resultPoints
;
if
(
points
==
null
)
{
return
[];
return
const
[];
}
return
points
.
toDart
.
cast
<
ResultPoint
>().
map
((
point
)
{
return
points
.
toDart
.
map
((
point
)
{
return
Offset
(
point
.
x
,
point
.
y
);
}).
toList
();
}
/// Get the raw bytes of the result.
Uint8List
?
get
rawBytes
=>
_rawBytes
?.
toDart
;
/// Get the text of the result.
String
?
get
text
=>
_text
?.
toDart
;
/// Get the timestamp of the result.
int
?
get
timestamp
=>
_timestamp
?.
toDartInt
;
/// Convert this result to a [Barcode].
Barcode
get
toBarcode
{
return
Barcode
(
...
...
lib/src/web/zxing/result_point.dart
View file @
f31b03d
...
...
@@ -3,21 +3,10 @@ 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/ResultPoint.ts
@JS
()
@anonymous
@staticInterop
abstract
class
ResultPoint
{}
extension
ResultPointExt
on
ResultPoint
{
@JS
(
'x'
)
external
JSNumber
get
_x
;
@JS
(
'y'
)
external
JSNumber
get
_y
;
extension
type
ResultPoint
(
JSObject
_
)
implements
JSObject
{
/// The x coordinate of the point.
double
get
x
=>
_x
.
toDartDouble
;
external
double
get
x
;
/// The y coordinate of the point.
double
get
y
=>
_y
.
toDartDouble
;
external
double
get
y
;
}
...
...
lib/src/web/zxing/zxing_barcode_reader.dart
View file @
f31b03d
...
...
@@ -48,42 +48,6 @@ final class ZXingBarcodeReader extends BarcodeReader {
@override
String
get
scriptUrl
=>
'https://unpkg.com/@zxing/library@0.19.1'
;
/// Get the barcode format from the ZXing library, for the given [format].
static
int
getZXingBarcodeFormat
(
BarcodeFormat
format
)
{
switch
(
format
)
{
case
BarcodeFormat
.
aztec
:
return
0
;
case
BarcodeFormat
.
codabar
:
return
1
;
case
BarcodeFormat
.
code39
:
return
2
;
case
BarcodeFormat
.
code93
:
return
3
;
case
BarcodeFormat
.
code128
:
return
4
;
case
BarcodeFormat
.
dataMatrix
:
return
5
;
case
BarcodeFormat
.
ean8
:
return
6
;
case
BarcodeFormat
.
ean13
:
return
7
;
case
BarcodeFormat
.
itf
:
return
8
;
case
BarcodeFormat
.
pdf417
:
return
10
;
case
BarcodeFormat
.
qrCode
:
return
11
;
case
BarcodeFormat
.
upcA
:
return
14
;
case
BarcodeFormat
.
upcE
:
return
15
;
case
BarcodeFormat
.
unknown
:
case
BarcodeFormat
.
all
:
default
:
return
-
1
;
}
}
JSMap
?
_createReaderHints
(
List
<
BarcodeFormat
>
formats
)
{
if
(
formats
.
isEmpty
||
formats
.
contains
(
BarcodeFormat
.
all
))
{
return
null
;
...
...
@@ -96,8 +60,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
hints
.
set
(
2
.
toJS
,
[
for
(
final
BarcodeFormat
format
in
formats
)
getZXingBarcodeFormat
(
format
).
toJS
,
for
(
final
BarcodeFormat
format
in
formats
)
format
.
toJS
,
].
toJS
,
);
...
...
@@ -185,7 +148,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
_reader
=
ZXingBrowserMultiFormatReader
(
_createReaderHints
(
formats
),
detectionTimeoutMs
.
toJS
,
detectionTimeoutMs
,
);
await
_prepareVideoElement
(
videoElement
,
videoStream
);
...
...
@@ -199,3 +162,24 @@ final class ZXingBarcodeReader extends BarcodeReader {
_reader
=
null
;
}
}
extension
on
BarcodeFormat
{
/// Get the barcode format from the ZXing library.
JSNumber
get
toJS
=>
switch
(
this
)
{
BarcodeFormat
.
aztec
=>
0
,
BarcodeFormat
.
codabar
=>
1
,
BarcodeFormat
.
code39
=>
2
,
BarcodeFormat
.
code93
=>
3
,
BarcodeFormat
.
code128
=>
4
,
BarcodeFormat
.
dataMatrix
=>
5
,
BarcodeFormat
.
ean8
=>
6
,
BarcodeFormat
.
ean13
=>
7
,
BarcodeFormat
.
itf
=>
8
,
BarcodeFormat
.
pdf417
=>
10
,
BarcodeFormat
.
qrCode
=>
11
,
BarcodeFormat
.
upcA
=>
14
,
BarcodeFormat
.
upcE
=>
15
,
BarcodeFormat
.
unknown
||
BarcodeFormat
.
all
||
_
=>
-
1
,
}
.
toJS
;
}
...
...
lib/src/web/zxing/zxing_browser_multi_format_reader.dart
View file @
f31b03d
...
...
@@ -7,8 +7,7 @@ import 'package:web/web.dart';
///
/// See https://github.com/zxing-js/library/blob/master/src/browser/BrowserMultiFormatReader.ts
@JS
(
'ZXing.BrowserMultiFormatReader'
)
@staticInterop
class
ZXingBrowserMultiFormatReader
{
extension
type
ZXingBrowserMultiFormatReader
.
_
(
JSObject
_
)
implements
JSObject
{
/// Construct a new `ZXing.BrowserMultiFormatReader`.
///
/// The [hints] are the configuration options for the reader.
...
...
@@ -17,11 +16,9 @@ class ZXingBrowserMultiFormatReader {
/// See also: https://github.com/zxing-js/library/blob/master/src/core/DecodeHintType.ts
external
factory
ZXingBrowserMultiFormatReader
(
JSMap
?
hints
,
JSNumber
?
timeBetweenScansMillis
,
int
timeBetweenScansMillis
,
);
}
extension
ZXingBrowserMultiFormatReaderExt
on
ZXingBrowserMultiFormatReader
{
/// Attach a [MediaStream] to a [HTMLVideoElement].
///
/// This function accepts a [MediaStream] and a [HTMLVideoElement] as arguments,
...
...
Please
register
or
login
to post a comment