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-04-09 16:15:49 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd6d5bd4cc1c454f8554bc89b4695f0cfc7c50da
cd6d5bd4
1 parent
d1325538
lazily set up the barcode reader on web
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
13 deletions
lib/src/web/mobile_scanner_web.dart
lib/src/web/mobile_scanner_web.dart
View file @
cd6d5bd
...
...
@@ -25,7 +25,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
String
?
_alternateScriptUrl
;
/// The internal barcode reader.
final
BarcodeReader
_barcodeReader
=
ZXingBarcodeReader
()
;
BarcodeReader
?
_barcodeReader
;
/// The stream controller for the barcode stream.
final
StreamController
<
BarcodeCapture
>
_barcodesController
=
...
...
@@ -221,11 +221,11 @@ class MobileScannerWeb extends MobileScannerPlatform {
@override
Widget
buildCameraView
()
{
if
(!
_barcodeReader
.
isScanning
)
{
return
const
SizedBox
();
if
(
_barcodeReader
?.
isScanning
??
false
)
{
return
HtmlElementView
(
viewType:
_getViewType
(
_textureId
));
}
return
HtmlElementView
(
viewType:
_getViewType
(
_textureId
)
);
return
const
SizedBox
(
);
}
@override
...
...
@@ -266,11 +266,13 @@ class MobileScannerWeb extends MobileScannerPlatform {
throw
PermissionRequestPendingException
();
}
await
_barcodeReader
.
maybeLoadLibrary
(
_barcodeReader
=
ZXingBarcodeReader
();
await
_barcodeReader
?.
maybeLoadLibrary
(
alternateScriptUrl:
_alternateScriptUrl
,
);
if
(
_barcodeReader
.
isScanning
)
{
if
(
_barcodeReader
?.
isScanning
??
false
)
{
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
controllerAlreadyInitialized
,
errorDetails:
MobileScannerErrorDetails
(
...
...
@@ -292,7 +294,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
}
// Listen for changes to the media track settings.
_barcodeReader
.
setMediaTrackSettingsListener
(
_barcodeReader
?
.
setMediaTrackSettingsListener
(
_handleMediaTrackSettingsChange
,
);
...
...
@@ -302,7 +304,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
_maybeFlipVideoPreview
(
_videoElement
,
videoStream
);
await
_barcodeReader
.
start
(
await
_barcodeReader
?
.
start
(
startOptions
,
videoElement:
_videoElement
,
videoStream:
videoStream
,
...
...
@@ -318,7 +320,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
}
try
{
_barcodesSubscription
=
_barcodeReader
.
detectBarcodes
().
listen
(
_barcodesSubscription
=
_barcodeReader
?
.
detectBarcodes
().
listen
(
(
BarcodeCapture
barcode
)
{
if
(
_barcodesController
.
isClosed
)
{
return
;
...
...
@@ -328,15 +330,15 @@ class MobileScannerWeb extends MobileScannerPlatform {
},
);
final
bool
hasTorch
=
await
_barcodeReader
.
hasTorch
()
;
final
bool
hasTorch
=
await
_barcodeReader
?.
hasTorch
()
??
false
;
if
(
hasTorch
&&
startOptions
.
torchEnabled
)
{
await
_barcodeReader
.
setTorchState
(
TorchState
.
on
);
await
_barcodeReader
?
.
setTorchState
(
TorchState
.
on
);
}
return
MobileScannerViewAttributes
(
hasTorch:
hasTorch
,
size:
_barcodeReader
.
videoSize
,
size:
_barcodeReader
?.
videoSize
??
Size
.
zero
,
);
}
catch
(
error
,
stackTrace
)
{
throw
MobileScannerException
(
...
...
@@ -359,7 +361,8 @@ class MobileScannerWeb extends MobileScannerPlatform {
await
_barcodesSubscription
?.
cancel
();
_barcodesSubscription
=
null
;
await
_barcodeReader
.
stop
();
await
_barcodeReader
?.
stop
();
_barcodeReader
=
null
;
}
@override
...
...
Please
register
or
login
to post a comment