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-29 11:01:21 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
536c4ac84ac26b5bfd80bb67f90afea95ab550e2
536c4ac8
1 parent
baf915f6
remove old permission workaround
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1 additions
and
40 deletions
lib/mobile_scanner.dart
lib/src/mobile_scanner_controller.dart
lib/src/mobile_scanner_exception.dart
lib/src/web/mobile_scanner_web.dart
lib/mobile_scanner.dart
View file @
536c4ac
...
...
@@ -11,8 +11,7 @@ export 'src/enums/phone_type.dart';
export
'src/enums/torch_state.dart'
;
export
'src/mobile_scanner.dart'
;
export
'src/mobile_scanner_controller.dart'
;
export
'src/mobile_scanner_exception.dart'
hide
PermissionRequestPendingException
;
export
'src/mobile_scanner_exception.dart'
;
export
'src/mobile_scanner_platform_interface.dart'
;
export
'src/objects/address.dart'
;
export
'src/objects/barcode.dart'
;
...
...
lib/src/mobile_scanner_controller.dart
View file @
536c4ac
...
...
@@ -242,13 +242,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
);
}
// Permission was denied, do nothing.
// When the controller is stopped,
// the error is reset so the permission can be requested again if possible.
if
(
value
.
error
?.
errorCode
==
MobileScannerErrorCode
.
permissionDenied
)
{
return
;
}
// Do nothing if the camera is already running.
if
(
value
.
isRunning
)
{
return
;
...
...
@@ -301,8 +294,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
zoomScale:
1.0
,
);
}
}
on
PermissionRequestPendingException
catch
(
_
)
{
// If a permission request was already pending, do nothing.
}
}
...
...
lib/src/mobile_scanner_exception.dart
View file @
536c4ac
...
...
@@ -39,10 +39,3 @@ class MobileScannerErrorDetails {
/// The error message from the [PlatformException].
final
String
?
message
;
}
/// This class represents an exception that is thrown
/// when the scanner was (re)started while a permission request was pending.
///
/// This exception type is only used internally,
/// and is not part of the public API.
class
PermissionRequestPendingException
implements
Exception
{}
...
...
lib/src/web/mobile_scanner_web.dart
View file @
536c4ac
...
...
@@ -38,12 +38,6 @@ class MobileScannerWeb extends MobileScannerPlatform {
/// The container div element for the camera view.
late
HTMLDivElement
_divElement
;
/// The flag that keeps track of whether a permission request is in progress.
///
/// On the web, a permission request triggers a dialog, that in turn triggers a lifecycle change.
/// While the permission request is in progress, any attempts at (re)starting the camera should be ignored.
bool
_permissionRequestInProgress
=
false
;
/// The stream controller for the media track settings stream.
///
/// Currently, only the facing mode setting can be supported,
...
...
@@ -187,14 +181,9 @@ class MobileScannerWeb extends MobileScannerPlatform {
try
{
// Retrieving the media devices requests the camera permission.
_permissionRequestInProgress
=
true
;
final
MediaStream
videoStream
=
await
window
.
navigator
.
mediaDevices
.
getUserMedia
(
constraints
).
toDart
;
// At this point the permission is granted.
_permissionRequestInProgress
=
false
;
return
videoStream
;
}
on
DOMException
catch
(
error
,
stackTrace
)
{
final
String
errorMessage
=
error
.
toString
();
...
...
@@ -209,10 +198,6 @@ class MobileScannerWeb extends MobileScannerPlatform {
errorCode
=
MobileScannerErrorCode
.
permissionDenied
;
}
// At this point the permission request completed, although with an error,
// but the error is irrelevant.
_permissionRequestInProgress
=
false
;
throw
MobileScannerException
(
errorCode:
errorCode
,
errorDetails:
MobileScannerErrorDetails
(
...
...
@@ -268,13 +253,6 @@ class MobileScannerWeb extends MobileScannerPlatform {
@override
Future
<
MobileScannerViewAttributes
>
start
(
StartOptions
startOptions
)
async
{
// If the permission request has not yet completed,
// the camera view is not ready yet.
// Prevent the permission popup from triggering a restart of the scanner.
if
(
_permissionRequestInProgress
)
{
throw
PermissionRequestPendingException
();
}
_barcodeReader
=
ZXingBarcodeReader
();
await
_barcodeReader
?.
maybeLoadLibrary
(
...
...
Please
register
or
login
to post a comment