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-02-14 15:49:40 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
901161a90fdaf7e11042ef2bd720ebfa72695a54
901161a9
1 parent
2aba3c53
format
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
example/lib/mobile_scanner_overlay.dart
lib/src/web/mobile_scanner_web.dart
example/lib/mobile_scanner_overlay.dart
View file @
901161a
...
...
@@ -6,7 +6,8 @@ import 'package:mobile_scanner_example/scanner_error_widget.dart';
class
BarcodeScannerWithOverlay
extends
StatefulWidget
{
@override
_BarcodeScannerWithOverlayState
createState
()
=>
_BarcodeScannerWithOverlayState
();
_BarcodeScannerWithOverlayState
createState
()
=>
_BarcodeScannerWithOverlayState
();
}
class
_BarcodeScannerWithOverlayState
extends
State
<
BarcodeScannerWithOverlay
>
{
...
...
@@ -58,7 +59,9 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
ValueListenableBuilder
(
valueListenable:
controller
,
builder:
(
context
,
value
,
child
)
{
if
(!
value
.
isInitialized
||
!
value
.
isRunning
||
value
.
error
!=
null
)
{
if
(!
value
.
isInitialized
||
!
value
.
isRunning
||
value
.
error
!=
null
)
{
return
const
SizedBox
();
}
...
...
@@ -151,6 +154,7 @@ class ScannerOverlay extends CustomPainter {
@override
bool
shouldRepaint
(
ScannerOverlay
oldDelegate
)
{
return
scanWindow
!=
oldDelegate
.
scanWindow
||
borderRadius
!=
oldDelegate
.
borderRadius
;
return
scanWindow
!=
oldDelegate
.
scanWindow
||
borderRadius
!=
oldDelegate
.
borderRadius
;
}
}
...
...
lib/src/web/mobile_scanner_web.dart
View file @
901161a
...
...
@@ -101,12 +101,14 @@ class MobileScannerWeb extends MobileScannerPlatform {
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
unsupported
,
errorDetails:
MobileScannerErrorDetails
(
message:
'This browser does not support displaying video from the camera.'
,
message:
'This browser does not support displaying video from the camera.'
,
),
);
}
final
MediaTrackSupportedConstraints
capabilities
=
window
.
navigator
.
mediaDevices
.
getSupportedConstraints
();
final
MediaTrackSupportedConstraints
capabilities
=
window
.
navigator
.
mediaDevices
.
getSupportedConstraints
();
final
MediaStreamConstraints
constraints
;
...
...
@@ -128,8 +130,9 @@ class MobileScannerWeb extends MobileScannerPlatform {
// If the completer is not null, the permission was never requested before.
_cameraPermissionCompleter
??=
Completer
<
void
>();
final
MediaStream
?
videoStream
=
await
window
.
navigator
.
mediaDevices
.
getUserMedia
(
constraints
).
toDart
as
MediaStream
?;
final
MediaStream
?
videoStream
=
await
window
.
navigator
.
mediaDevices
.
getUserMedia
(
constraints
)
.
toDart
as
MediaStream
?;
// At this point the permission is granted.
if
(!
_cameraPermissionCompleter
!.
isCompleted
)
{
...
...
@@ -140,7 +143,8 @@ class MobileScannerWeb extends MobileScannerPlatform {
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
genericError
,
errorDetails:
MobileScannerErrorDetails
(
message:
'Could not create a video stream from the camera with the given options. '
message:
'Could not create a video stream from the camera with the given options. '
'The browser might not support the given constraints.'
,
),
);
...
...
@@ -159,7 +163,8 @@ class MobileScannerWeb extends MobileScannerPlatform {
MobileScannerErrorCode
errorCode
=
MobileScannerErrorCode
.
genericError
;
// Handle both unsupported and permission errors from the web.
if
(
errorMessage
.
contains
(
'NotFoundError'
)
||
errorMessage
.
contains
(
'NotSupportedError'
))
{
if
(
errorMessage
.
contains
(
'NotFoundError'
)
||
errorMessage
.
contains
(
'NotSupportedError'
))
{
errorCode
=
MobileScannerErrorCode
.
unsupported
;
}
else
if
(
errorMessage
.
contains
(
'NotAllowedError'
))
{
errorCode
=
MobileScannerErrorCode
.
permissionDenied
;
...
...
Please
register
or
login
to post a comment