Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
permission_handler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
permission_handler
Commits
32c7e941
Commit
32c7e941
authored
Mar 17, 2021
by
Jan-Derk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test
parent
3828b56f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
141 additions
and
6 deletions
+141
-6
permission_handler/CHANGELOG.md
+4
-0
permission_handler/README.md
+1
-1
permission_handler/lib/permission_handler.dart
+2
-3
permission_handler/pubspec.yaml
+5
-2
permission_handler/test/permission_handler_test.dart
+129
-0
No files found.
permission_handler/CHANGELOG.md
View file @
32c7e941
## 6.1.1
*
Added unit-tests to guard API against breaking changes.
## 6.1.0
*
Added support for bluetooth permissions;
...
...
permission_handler/README.md
View file @
32c7e941
[

](https://pub.dartlang.org/packages/permission_handler)
[

](https://github.com/Baseflow/flutter-permission-handler/actions/workflows/app_facing_package.yaml)
[

](https://github.com/tenhobi/effective_dart)
[

](https://pub.dartlang.org/packages/permission_handler)
[

](https://github.com/Baseflow/flutter-permission-handler/actions/workflows/app_facing_package.yaml)
[

](https://github.com/tenhobi/effective_dart)
[

](https://codecov.io/gh/Baseflow/flutter-permission-handler)
On most operating systems, permissions aren't just granted to apps at install time.
Rather, developers have to ask the user for permissions while the app is running.
...
...
permission_handler/lib/permission_handler.dart
View file @
32c7e941
import
'dart:io'
;
import
'package:flutter/foundation.dart'
;
import
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
;
export
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
...
...
@@ -34,7 +33,7 @@ extension PermissionActions on Permission {
/// This is only implemented on Android, calling this on iOS always returns
/// [false].
Future
<
bool
>
get
shouldShowRequestRationale
async
{
if
(
!
Platform
.
isA
ndroid
)
{
if
(
defaultTargetPlatform
!=
TargetPlatform
.
a
ndroid
)
{
return
false
;
}
...
...
permission_handler/pubspec.yaml
View file @
32c7e941
name
:
permission_handler
description
:
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
version
:
6.1.
0
version
:
6.1.
1
homepage
:
https://github.com/baseflowit/flutter-permission-handler
flutter
:
...
...
@@ -16,9 +16,12 @@ dependencies:
flutter
:
sdk
:
flutter
meta
:
^1.3.0
permission_handler_platform_interface
:
^3.1.
0
permission_handler_platform_interface
:
^3.1.
1
dev_dependencies
:
flutter_test
:
sdk
:
flutter
mockito
:
^5.0.1
effective_dart
:
^1.3.0
plugin_platform_interface
:
^2.0.0
...
...
permission_handler/test/permission_handler_test.dart
0 → 100644
View file @
32c7e941
import
'package:flutter_test/flutter_test.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:permission_handler/permission_handler.dart'
;
import
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
;
import
'package:plugin_platform_interface/plugin_platform_interface.dart'
;
void
main
(
)
{
group
(
'PermissionHandler'
,
()
{
setUp
(()
{
PermissionHandlerPlatform
.
instance
=
MockPermissionHandlerPlatform
();
});
test
(
'openAppSettings'
,
()
async
{
final
hasOpened
=
await
openAppSettings
();
expect
(
hasOpened
,
true
);
});
test
(
'PermissionActions on Permission: get status'
,
()
async
{
final
permissionStatus
=
await
Permission
.
calendar
.
status
;
expect
(
permissionStatus
,
PermissionStatus
.
granted
);
});
test
(
// ignore: lines_longer_than_80_chars
'PermissionActions on Permission: get shouldShowRequestRationale should return true when on android'
,
()
async
{
final
mockPermissionHandlerPlatform
=
PermissionHandlerPlatform
.
instance
;
when
(
mockPermissionHandlerPlatform
.
shouldShowRequestPermissionRationale
(
Permission
.
calendar
))
.
thenAnswer
((
_
)
=>
Future
.
value
(
true
));
await
Permission
.
calendar
.
shouldShowRequestRationale
;
verify
(
mockPermissionHandlerPlatform
.
shouldShowRequestPermissionRationale
(
Permission
.
calendar
))
.
called
(
1
);
});
test
(
'PermissionActions on Permission: request()'
,
()
async
{
final
permissionRequest
=
Permission
.
calendar
.
request
();
expect
(
permissionRequest
,
isA
<
Future
<
PermissionStatus
>>());
});
test
(
'PermissionCheckShortcuts on Permission: get isGranted'
,
()
async
{
final
isGranted
=
await
Permission
.
calendar
.
isGranted
;
expect
(
isGranted
,
true
);
});
test
(
'PermissionCheckShortcuts on Permission: get isDenied'
,
()
async
{
final
isDenied
=
await
Permission
.
calendar
.
isDenied
;
expect
(
isDenied
,
false
);
});
test
(
'PermissionCheckShortcuts on Permission: get isRestricted'
,
()
async
{
final
isRestricted
=
await
Permission
.
calendar
.
isRestricted
;
expect
(
isRestricted
,
false
);
});
test
(
'PermissionCheckShortcuts on Permission: get isLimited'
,
()
async
{
final
isLimited
=
await
Permission
.
calendar
.
isLimited
;
expect
(
isLimited
,
false
);
});
test
(
'PermissionCheckShortcuts on Permission: get isPermanentlyDenied'
,
()
async
{
final
isPermanentlyDenied
=
await
Permission
.
calendar
.
isPermanentlyDenied
;
expect
(
isPermanentlyDenied
,
false
);
});
test
(
// ignore: lines_longer_than_80_chars
'ServicePermissionActions on PermissionWithService: get ServiceStatus returns the right service status'
,
()
async
{
var
serviceStatus
=
await
Permission
.
phone
.
serviceStatus
;
expect
(
serviceStatus
,
ServiceStatus
.
enabled
);
});
test
(
// ignore: lines_longer_than_80_chars
'PermissionListActions on List<Permission>: request() on a list returns a Map<Permission, PermissionStatus>'
,
()
async
{
var
permissionList
=
<
Permission
>[];
final
permissionMap
=
await
permissionList
.
request
();
expect
(
permissionMap
,
isA
<
Map
<
Permission
,
PermissionStatus
>>());
});
});
}
class
MockPermissionHandlerPlatform
extends
Mock
with
// ignore: prefer_mixin
MockPlatformInterfaceMixin
implements
PermissionHandlerPlatform
{
@override
Future
<
PermissionStatus
>
checkPermissionStatus
(
Permission
permission
)
=>
Future
.
value
(
PermissionStatus
.
granted
);
@override
Future
<
ServiceStatus
>
checkServiceStatus
(
Permission
permission
)
=>
Future
.
value
(
ServiceStatus
.
enabled
);
@override
Future
<
bool
>
openAppSettings
()
=>
Future
.
value
(
true
);
@override
Future
<
Map
<
Permission
,
PermissionStatus
>>
requestPermissions
(
List
<
Permission
>
permissions
)
{
var
permissionsMap
=
<
Permission
,
PermissionStatus
>{};
return
Future
.
value
(
permissionsMap
);
}
@override
Future
<
bool
>
shouldShowRequestPermissionRationale
(
Permission
?
permission
)
{
return
super
.
noSuchMethod
(
Invocation
.
method
(
#shouldShowPermissionRationale
,
[
permission
],
),
returnValue:
Future
.
value
(
true
),
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment