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
97fb6959
Commit
97fb6959
authored
Mar 08, 2020
by
Marcel Garus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new api
parent
7506ff7d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
28 deletions
+92
-28
permission_handler/lib/permission_handler.dart
+92
-28
No files found.
permission_handler/lib/permission_handler.dart
View file @
97fb6959
import
'dart:async'
;
import
'dart:io'
;
import
'dart:io'
;
import
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
;
import
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
;
export
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
export
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
show
Permission
Group
,
PermissionStatus
,
ServiceStatus
;
show
Permission
,
PermissionStatus
,
ServiceStatus
;
/// The Android and iOS implementation of [PermissionHandlerPlatform].
PermissionHandlerPlatform
get
_handler
=>
PermissionHandlerPlatform
.
instance
;
/// Opens the app settings page.
///
///
/// This class implements the `package:permission_handler` functionality for
/// Returns [true] if the app settings page could be opened, otherwise [false].
/// the Android and iOS platforms.
Future
<
bool
>
openAppSettings
()
=>
_handler
.
openAppSettings
();
class
PermissionHandler
extends
PermissionHandlerPlatform
{
@override
Future
<
ServiceStatus
>
checkServiceStatus
(
PermissionGroup
permission
)
{
return
PermissionHandlerPlatform
.
instance
.
checkServiceStatus
(
permission
);
}
@override
/// Actions that can be executed on a permission.
Future
<
PermissionStatus
>
checkPermissionStatus
(
PermissionGroup
permission
)
{
extension
PermissionActions
on
Permission
{
return
PermissionHandlerPlatform
.
instance
.
checkPermissionStatus
(
permission
);
/// The current status of this permission.
}
Future
<
PermissionStatus
>
get
status
=>
_handler
.
checkPermissionStatus
(
this
);
/// If you should show a rationale for requesting permission.
///
/// This is only implemented on Android, calling this on iOS always returns
/// [false].
Future
<
bool
>
get
shouldShowRequestRationale
{
if
(!
Platform
.
isAndroid
)
{
return
Future
.
value
(
false
);
}
@override
return
_handler
.
shouldShowRequestPermissionRationale
(
this
);
Future
<
bool
>
openAppSettings
()
{
return
PermissionHandlerPlatform
.
instance
.
openAppSettings
();
}
}
@override
/// Request the user for access to this permission.
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
///
List
<
PermissionGroup
>
permissions
)
{
/// Returns the new [PermissionStatus].
return
PermissionHandlerPlatform
.
instance
.
requestPermissions
(
permissions
);
Future
<
PermissionStatus
>
request
()
async
{
return
(
await
[
this
].
request
())[
this
];
}
}
@override
/// Request the user for access to this permission if it [isDenied].
Future
<
bool
>
shouldShowRequestPermissionRationale
(
///
PermissionGroup
permission
)
{
/// Returns the new [PermissionStatus].
if
(!
Platform
.
isAndroid
)
{
Future
<
PermissionStatus
>
requestIfDenied
()
async
{
return
Future
.
value
(
false
);
final
status
=
await
this
.
status
;
if
(
status
.
isDenied
)
{
return
request
();
}
}
return
status
;
}
}
/// Shortcuts for checking the [status] of a permission.
extension
PermissionCheckShortcuts
on
Permission
{
/// If the user denied access to the requested feature.
Future
<
bool
>
get
isDenied
=>
status
.
isDenied
;
/// If the user granted access to the requested feature.
Future
<
bool
>
get
isGranted
=>
status
.
isGranted
;
/// If the OS denied access to the requested feature. The user cannot change
/// this app's status, possibly due to active restrictions such as parental
/// controls being in place.
/// *Only supported on iOS.*
Future
<
bool
>
get
isRestricted
=>
status
.
isRestricted
;
/// If the permission is in an unknown state.
Future
<
bool
>
get
isUnknown
=>
status
.
isUnknown
;
/// If the user denied access to the requested feature and selected to never
/// again show a request for this permission.
/// *Only supported on Android.*
Future
<
bool
>
get
isNeverAskedAgain
=>
status
.
isNeverAskAgain
;
}
/// Actions that apply only to permissions that have an associated service.
extension
ServicePermissionActions
on
ServicePermission
{
/// The current status of the service associated with this permission.
///
/// Notes about specific permissions:
/// - **[Permission.phone]**
/// - Android:
/// - The method will return [ServiceStatus.notApplicable] when:
/// 1. the device lacks the TELEPHONY feature
/// 2. TelephonyManager.getPhoneType() returns PHONE_TYPE_NONE
/// 3. when no Intents can be resolved to handle the `tel:` scheme
/// - The method will return [ServiceStatus.disabled] when:
/// 1. the SIM card is missing
/// - iOS:
/// - The method will return [ServiceStatus.notApplicable] when:
/// 1. the native code can not find a handler for the `tel:` scheme
/// - The method will return [ServiceStatus.disabled] when:
/// 1. the mobile network code (MNC) is either 0 or 65535. See
/// https://stackoverflow.com/a/11595365 for details
/// - **PLEASE NOTE that this is still not a perfect indication** of the
/// devices' capability to place & connect phone calls
/// as it also depends on the network condition.
Future
<
ServiceStatus
>
get
serviceStatus
=>
_handler
.
checkServiceStatus
(
this
);
}
return
PermissionHandlerPlatform
.
instance
/// Actions that can be taken on a [List] of [Permission]s.
.
shouldShowRequestPermissionRationale
(
permission
);
extension
PermissionListActions
on
List
<
Permission
>
{
/// Request the user for access to this list of permissions.
///
/// Returns a [Map] containing the [PermissionStatus] per requested
/// [Permission].
Future
<
Map
<
Permission
,
PermissionStatus
>>
request
()
{
return
_handler
.
requestPermissions
(
this
);
}
}
}
}
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