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:05:08 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a053e85aa092c8ce2c60ddd76a217817dd6380be
a053e85a
1 parent
27b4d0f5
refactor: abstract torch support
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
22 deletions
lib/mobile_scanner_web_plugin.dart
lib/src/web/base.dart
lib/src/web/jsqr.dart
lib/mobile_scanner_web_plugin.dart
View file @
a053e85
...
...
@@ -34,9 +34,6 @@ class MobileScannerWebPlugin {
// ID of the video feed
String
viewID
=
'WebScanner-
${DateTime.now().millisecondsSinceEpoch}
'
;
// Determine wether device has flas
bool
hasFlash
=
false
;
final
html
.
DivElement
vidDiv
=
html
.
DivElement
();
late
final
WebBarcodeReaderBase
_barCodeReader
=
...
...
@@ -63,15 +60,7 @@ class MobileScannerWebPlugin {
/// Can enable or disable the flash if available
Future
<
void
>
_torch
(
arguments
)
async
{
// if (hasFlash) {
// final track = _localStream?.getVideoTracks();
// await track!.first.applyConstraints({
// 'advanced': {'torch': arguments == 1}
// });
// } else {
// controller.addError('Device has no flash');
// }
controller
.
addError
(
'Device has no flash'
);
_barCodeReader
.
toggleTorch
(
enabled:
arguments
==
1
);
}
/// Starts the video stream and the scanner
...
...
@@ -97,7 +86,8 @@ class MobileScannerWebPlugin {
return
{
'ViewID'
:
viewID
,
'videoWidth'
:
_barCodeReader
.
videoWidth
,
'videoHeight'
:
_barCodeReader
.
videoHeight
'videoHeight'
:
_barCodeReader
.
videoHeight
,
'torchable'
:
_barCodeReader
.
hasTorch
,
};
}
try
{
...
...
@@ -115,7 +105,7 @@ class MobileScannerWebPlugin {
'ViewID'
:
viewID
,
'videoWidth'
:
_barCodeReader
.
videoWidth
,
'videoHeight'
:
_barCodeReader
.
videoHeight
,
'torchable'
:
hasFlash
'torchable'
:
_barCodeReader
.
hasTorch
,
};
}
catch
(
e
)
{
throw
PlatformException
(
code:
'MobileScannerWeb'
,
message:
'
$e
'
);
...
...
lib/src/web/base.dart
View file @
a053e85
...
...
@@ -29,6 +29,12 @@ abstract class WebBarcodeReaderBase {
/// Stops streaming video
Future
<
void
>
stop
();
/// Can enable or disable the flash if available
Future
<
void
>
toggleTorch
({
required
bool
enabled
});
/// Determine whether device has flash
bool
get
hasTorch
;
}
mixin
InternalStreamCreation
on
WebBarcodeReaderBase
{
...
...
@@ -86,3 +92,30 @@ mixin InternalStreamCreation on WebBarcodeReaderBase {
videoContainer
.
children
=
[];
}
}
/// Mixin for libraries that don't have built-in torch support
mixin
InternalTorchDetection
on
InternalStreamCreation
{
@override
bool
get
hasTorch
{
// TODO: fix flash light. See https://github.com/dart-lang/sdk/issues/48533
// final track = _localStream?.getVideoTracks();
// if (track != null) {
// final imageCapture = html.ImageCapture(track.first);
// final photoCapabilities = await imageCapture.getPhotoCapabilities();
// }
return
false
;
}
@override
Future
<
void
>
toggleTorch
({
required
bool
enabled
})
async
{
if
(
hasTorch
)
{
final
track
=
localMediaStream
?.
getVideoTracks
();
await
track
?.
first
.
applyConstraints
({
'advanced'
:
[
{
'torch'
:
enabled
}
]
});
}
}
}
...
...
lib/src/web/jsqr.dart
View file @
a053e85
...
...
@@ -20,7 +20,8 @@ class Code {
}
class
JsQrCodeReader
extends
WebBarcodeReaderBase
with
InternalStreamCreation
{
class
JsQrCodeReader
extends
WebBarcodeReaderBase
with
InternalStreamCreation
,
InternalTorchDetection
{
JsQrCodeReader
({
required
super
.
videoContainer
});
@override
...
...
@@ -34,13 +35,6 @@ class JsQrCodeReader extends WebBarcodeReaderBase with InternalStreamCreation {
final
stream
=
await
initMediaStream
(
cameraFacing
);
// TODO: fix flash light. See https://github.com/dart-lang/sdk/issues/48533
// final track = _localStream?.getVideoTracks();
// if (track != null) {
// final imageCapture = html.ImageCapture(track.first);
// final photoCapabilities = await imageCapture.getPhotoCapabilities();
// }
prepareVideoElement
(
video
);
if
(
stream
!=
null
)
{
await
attachStreamToVideo
(
stream
,
video
);
...
...
Please
register
or
login
to post a comment