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 16:57:42 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8be5281e88ccdef26b6a5c84011f1baea2bfc837
8be5281e
1 parent
bf320d59
rename mobile scanner state enum
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
27 deletions
lib/mobile_scanner.dart
lib/src/enums/mobile_scanner_state.dart → lib/src/enums/mobile_scanner_authorization_state.dart
lib/src/method_channel/mobile_scanner_method_channel.dart
test/enums/mobile_scanner_state_test.dart → test/enums/mobile_scanner_authorization_state_test.dart
lib/mobile_scanner.dart
View file @
8be5281
...
...
@@ -5,8 +5,8 @@ export 'src/enums/camera_facing.dart';
export
'src/enums/detection_speed.dart'
;
export
'src/enums/email_type.dart'
;
export
'src/enums/encryption_type.dart'
;
export
'src/enums/mobile_scanner_authorization_state.dart'
;
export
'src/enums/mobile_scanner_error_code.dart'
;
export
'src/enums/mobile_scanner_state.dart'
;
export
'src/enums/phone_type.dart'
;
export
'src/enums/torch_state.dart'
;
export
'src/mobile_scanner.dart'
;
...
...
lib/src/enums/mobile_scanner_state.dart → lib/src/enums/mobile_scanner_
authorization_
state.dart
View file @
8be5281
/// The authorization state of the scanner.
enum
MobileScannerState
{
enum
MobileScanner
Authorization
State
{
/// The scanner has not yet requested the required permissions.
undetermined
(
0
),
...
...
@@ -9,16 +9,16 @@ enum MobileScannerState {
/// The user denied the required permissions.
denied
(
2
);
const
MobileScannerState
(
this
.
rawValue
);
const
MobileScanner
Authorization
State
(
this
.
rawValue
);
factory
MobileScannerState
.
fromRawValue
(
int
value
)
{
factory
MobileScanner
Authorization
State
.
fromRawValue
(
int
value
)
{
switch
(
value
)
{
case
0
:
return
MobileScannerState
.
undetermined
;
return
MobileScanner
Authorization
State
.
undetermined
;
case
1
:
return
MobileScannerState
.
authorized
;
return
MobileScanner
Authorization
State
.
authorized
;
case
2
:
return
MobileScannerState
.
denied
;
return
MobileScanner
Authorization
State
.
denied
;
default
:
throw
ArgumentError
.
value
(
value
,
'value'
,
'Invalid raw value.'
);
}
...
...
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
8be5281
...
...
@@ -4,8 +4,8 @@ import 'dart:io';
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:mobile_scanner/src/enums/barcode_format.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_authorization_state.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_state.dart'
;
import
'package:mobile_scanner/src/enums/torch_state.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_exception.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_platform_interface.dart'
;
...
...
@@ -92,10 +92,10 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
///
/// Throws a [MobileScannerException] if the permission is not granted.
Future
<
void
>
_requestCameraPermission
()
async
{
final
MobileScannerState
authorizationState
;
final
MobileScanner
Authorization
State
authorizationState
;
try
{
authorizationState
=
MobileScannerState
.
fromRawValue
(
authorizationState
=
MobileScanner
Authorization
State
.
fromRawValue
(
await
methodChannel
.
invokeMethod
<
int
>(
'state'
)
??
0
,
);
}
on
PlatformException
catch
(
error
)
{
...
...
@@ -111,13 +111,13 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
}
switch
(
authorizationState
)
{
case
MobileScannerState
.
denied
:
case
MobileScanner
Authorization
State
.
denied
:
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
permissionDenied
,
);
case
MobileScannerState
.
authorized
:
case
MobileScanner
Authorization
State
.
authorized
:
return
;
// Already authorized.
case
MobileScannerState
.
undetermined
:
case
MobileScanner
Authorization
State
.
undetermined
:
try
{
final
bool
permissionResult
=
await
methodChannel
.
invokeMethod
<
bool
>(
'request'
)
??
false
;
...
...
test/enums/mobile_scanner_state_test.dart → test/enums/mobile_scanner_
authorization_
state_test.dart
View file @
8be5281
import
'package:flutter_test/flutter_test.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_state.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_
authorization_
state.dart'
;
void
main
(
)
{
group
(
'
$MobileScannerState
tests'
,
()
{
group
(
'
$MobileScanner
Authorization
State
tests'
,
()
{
test
(
'can be created from raw value'
,
()
{
const
values
=
{
0
:
MobileScannerState
.
undetermined
,
1
:
MobileScannerState
.
authorized
,
2
:
MobileScannerState
.
denied
,
0
:
MobileScannerAuthorizationState
.
undetermined
,
1
:
MobileScannerAuthorizationState
.
authorized
,
2
:
MobileScannerAuthorizationState
.
denied
,
};
for
(
final
MapEntry
<
int
,
MobileScannerState
>
entry
in
values
.
entries
)
{
final
MobileScannerState
result
=
MobileScannerState
.
fromRawValue
(
for
(
final
MapEntry
<
int
,
MobileScannerAuthorizationState
>
entry
in
values
.
entries
)
{
final
MobileScannerAuthorizationState
result
=
MobileScannerAuthorizationState
.
fromRawValue
(
entry
.
key
,
);
...
...
@@ -24,23 +24,23 @@ void main() {
const
int
outOfRange
=
3
;
expect
(
()
=>
MobileScannerState
.
fromRawValue
(
negative
),
()
=>
MobileScanner
Authorization
State
.
fromRawValue
(
negative
),
throwsArgumentError
,
);
expect
(
()
=>
MobileScannerState
.
fromRawValue
(
outOfRange
),
()
=>
MobileScanner
Authorization
State
.
fromRawValue
(
outOfRange
),
throwsArgumentError
,
);
});
test
(
'can be converted to raw value'
,
()
{
const
values
=
<
MobileScannerState
,
int
>{
MobileScannerState
.
undetermined
:
0
,
MobileScannerState
.
authorized
:
1
,
MobileScannerState
.
denied
:
2
,
const
values
=
<
MobileScannerAuthorizationState
,
int
>{
MobileScannerAuthorizationState
.
undetermined
:
0
,
MobileScannerAuthorizationState
.
authorized
:
1
,
MobileScannerAuthorizationState
.
denied
:
2
,
};
for
(
final
MapEntry
<
MobileScannerState
,
int
>
entry
in
values
.
entries
)
{
for
(
final
MapEntry
<
MobileScanner
Authorization
State
,
int
>
entry
in
values
.
entries
)
{
final
int
result
=
entry
.
key
.
rawValue
;
expect
(
result
,
entry
.
value
);
...
...
Please
register
or
login
to post a comment