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
p-mazhnik
2022-11-22 14:35:02 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
292716bec51aebab51c45a883b56f22cbc232e00
292716be
1 parent
a053e85a
refactor(web): support additional barcode properties
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
5 deletions
lib/mobile_scanner_web_plugin.dart
lib/src/mobile_scanner_controller.dart
lib/src/web/base.dart
lib/src/web/jsqr.dart
lib/mobile_scanner_web_plugin.dart
View file @
292716b
...
...
@@ -97,7 +97,13 @@ class MobileScannerWebPlugin {
_barCodeStreamSubscription
=
_barCodeReader
.
detectBarcodeContinuously
().
listen
((
code
)
{
if
(
code
!=
null
)
{
controller
.
add
({
'name'
:
'barcodeWeb'
,
'data'
:
code
});
controller
.
add
({
'name'
:
'barcodeWeb'
,
'data'
:
{
'rawValue'
:
code
.
rawValue
,
'rawBytes'
:
code
.
rawBytes
,
},
});
}
});
...
...
lib/src/mobile_scanner_controller.dart
View file @
292716b
import
'dart:async'
;
import
'dart:io'
;
import
'dart:typed_data'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
...
...
@@ -296,11 +297,13 @@ class MobileScannerController {
);
break
;
case
'barcodeWeb'
:
final
barcode
=
data
as
Map
?;
_barcodesController
.
add
(
BarcodeCapture
(
barcodes:
[
Barcode
(
rawValue:
data
as
String
?,
rawValue:
barcode
?[
'rawValue'
]
as
String
?,
rawBytes:
barcode
?[
'rawBytes'
]
as
Uint8List
?,
)
],
),
...
...
lib/src/web/base.dart
View file @
292716b
...
...
@@ -2,6 +2,7 @@ import 'dart:html';
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/src/enums/camera_facing.dart'
;
import
'package:mobile_scanner/src/objects/barcode.dart'
;
import
'package:mobile_scanner/src/web/media.dart'
;
abstract
class
WebBarcodeReaderBase
{
...
...
@@ -25,7 +26,7 @@ abstract class WebBarcodeReaderBase {
});
/// Starts scanning QR codes or barcodes
Stream
<
String
?>
detectBarcodeContinuously
();
Stream
<
Barcode
?>
detectBarcodeContinuously
();
/// Stops streaming video
Future
<
void
>
stop
();
...
...
lib/src/web/jsqr.dart
View file @
292716b
...
...
@@ -7,6 +7,7 @@ import 'dart:typed_data';
import
'package:js/js.dart'
;
import
'package:mobile_scanner/src/enums/camera_facing.dart'
;
import
'package:mobile_scanner/src/objects/barcode.dart'
;
import
'package:mobile_scanner/src/web/base.dart'
;
@JS
(
'jsQR'
)
...
...
@@ -58,10 +59,20 @@ class JsQrCodeReader extends WebBarcodeReaderBase
}
@override
Stream
<
String
?>
detectBarcodeContinuously
()
async
*
{
Stream
<
Barcode
?>
detectBarcodeContinuously
()
async
*
{
yield
*
Stream
.
periodic
(
frameInterval
,
(
_
)
{
return
_captureFrame
(
video
);
}).
asyncMap
((
e
)
=>
e
).
map
((
event
)
=>
event
?.
data
);
}).
asyncMap
((
event
)
async
{
final
code
=
await
event
;
if
(
code
==
null
)
{
return
null
;
}
return
Barcode
(
rawValue:
code
.
data
,
rawBytes:
Uint8List
.
fromList
(
code
.
binaryData
),
format:
BarcodeFormat
.
qrCode
,
);
});
}
/// Captures a frame and analyzes it for QR codes
...
...
Please
register
or
login
to post a comment