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
2023-11-08 14:13:37 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
83a8db5b3424865458806061f9f8e1bbfed7db21
83a8db5b
1 parent
eaf9c70d
implement request permission for native
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
lib/src/method_channel/mobile_scanner_method_channel.dart
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
83a8db5
...
...
@@ -87,6 +87,60 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
);
}
/// Request permission to access the camera.
///
/// Throws a [MobileScannerException] if the permission is not granted.
Future
<
void
>
_requestCameraPermission
()
async
{
final
MobileScannerState
authorizationState
;
try
{
authorizationState
=
MobileScannerState
.
fromRawValue
(
await
methodChannel
.
invokeMethod
<
int
>(
'state'
)
??
0
,
);
}
on
PlatformException
catch
(
error
)
{
// If the permission state is invalid, that is an error.
throw
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
genericError
,
errorDetails:
MobileScannerErrorDetails
(
code:
error
.
code
,
details:
error
.
details
as
Object
?,
message:
error
.
message
,
),
);
}
switch
(
authorizationState
)
{
case
MobileScannerState
.
denied
:
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
permissionDenied
,
);
case
MobileScannerState
.
authorized
:
return
;
// Already authorized.
case
MobileScannerState
.
undetermined
:
try
{
final
bool
permissionResult
=
await
methodChannel
.
invokeMethod
<
bool
>(
'request'
)
??
false
;
if
(
permissionResult
)
{
return
;
// Authorization was granted.
}
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
permissionDenied
,
);
}
on
PlatformException
catch
(
error
)
{
// If the permission state is invalid, that is an error.
throw
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
genericError
,
errorDetails:
MobileScannerErrorDetails
(
code:
error
.
code
,
details:
error
.
details
as
Object
?,
message:
error
.
message
,
),
);
}
}
}
@override
Stream
<
BarcodeCapture
?>
get
barcodesStream
{
return
eventsStream
.
where
((
event
)
=>
event
[
'name'
]
==
'barcode'
).
map
((
event
)
=>
_parseBarcode
(
event
));
...
...
Please
register
or
login
to post a comment