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
f2489489
Commit
f2489489
authored
Sep 03, 2018
by
Martijn van Dijk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make methods non static
parent
e79c840a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
lib/permission_handler.dart
+25
-10
No files found.
lib/permission_handler.dart
View file @
f2489489
...
@@ -5,19 +5,34 @@ import 'dart:convert';
...
@@ -5,19 +5,34 @@ import 'dart:convert';
import
'dart:io'
;
import
'dart:io'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:meta/meta.dart'
;
part
'package:permission_handler/permission_enums.dart'
;
part
'package:permission_handler/permission_enums.dart'
;
part
'package:permission_handler/utils/codec.dart'
;
part
'package:permission_handler/utils/codec.dart'
;
/// Provides a cross-platform (iOS, Android) API to request and check permissions.
/// Provides a cross-platform (iOS, Android) API to request and check permissions.
class
PermissionHandler
{
class
PermissionHandler
{
static
const
MethodChannel
_channel
=
factory
PermissionHandler
()
{
const
MethodChannel
(
'flutter.baseflow.com/permissions/methods'
);
if
(
_instance
==
null
)
{
final
MethodChannel
methodChannel
=
const
MethodChannel
(
'flutter.baseflow.com/permissions/methods'
);
_instance
=
new
PermissionHandler
.
private
(
methodChannel
);
}
return
_instance
;
}
@visibleForTesting
PermissionHandler
.
private
(
this
.
_methodChannel
);
static
PermissionHandler
_instance
;
final
MethodChannel
_methodChannel
;
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
static
Future
<
PermissionStatus
>
checkPermissionStatus
(
Future
<
PermissionStatus
>
checkPermissionStatus
(
PermissionGroup
permission
)
async
{
PermissionGroup
permission
)
async
{
final
dynamic
status
=
await
_
c
hannel
.
invokeMethod
(
final
dynamic
status
=
await
_
methodC
hannel
.
invokeMethod
(
'checkPermissionStatus'
,
Codec
.
encodePermissionGroup
(
permission
));
'checkPermissionStatus'
,
Codec
.
encodePermissionGroup
(
permission
));
return
Codec
.
decodePermissionStatus
(
status
);
return
Codec
.
decodePermissionStatus
(
status
);
...
@@ -26,19 +41,19 @@ class PermissionHandler {
...
@@ -26,19 +41,19 @@ class PermissionHandler {
/// Open the App settings page.
/// Open the App settings page.
///
///
/// Returns [true] if the app settings page could be opened, otherwise [false] is returned.
/// Returns [true] if the app settings page could be opened, otherwise [false] is returned.
static
Future
<
bool
>
openAppSettings
()
async
{
Future
<
bool
>
openAppSettings
()
async
{
final
bool
hasOpened
=
await
_
c
hannel
.
invokeMethod
(
'openAppSettings'
);
final
bool
hasOpened
=
await
_
methodC
hannel
.
invokeMethod
(
'openAppSettings'
);
return
hasOpened
;
return
hasOpened
;
}
}
/// Request the user for access to the supplied list of permissiongroups.
/// Request the user for access to the supplied list of permissiongroups.
///
///
/// Returns a [Map] containing the status per requested permissiongroup.
/// Returns a [Map] containing the status per requested permissiongroup.
static
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
List
<
PermissionGroup
>
permissions
)
async
{
List
<
PermissionGroup
>
permissions
)
async
{
final
String
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
String
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
dynamic
status
=
final
dynamic
status
=
await
_
c
hannel
.
invokeMethod
(
'requestPermissions'
,
jsonData
);
await
_
methodC
hannel
.
invokeMethod
(
'requestPermissions'
,
jsonData
);
return
Codec
.
decodePermissionRequestResult
(
status
);
return
Codec
.
decodePermissionRequestResult
(
status
);
}
}
...
@@ -47,13 +62,13 @@ class PermissionHandler {
...
@@ -47,13 +62,13 @@ class PermissionHandler {
///
///
/// This method is only implemented on Android, calling this on iOS always
/// This method is only implemented on Android, calling this on iOS always
/// returns [false].
/// returns [false].
static
Future
<
bool
>
shouldShowRequestPermissionRationale
(
Future
<
bool
>
shouldShowRequestPermissionRationale
(
PermissionGroup
permission
)
async
{
PermissionGroup
permission
)
async
{
if
(!
Platform
.
isAndroid
)
{
if
(!
Platform
.
isAndroid
)
{
return
false
;
return
false
;
}
}
final
bool
shouldShowRationale
=
await
_
c
hannel
.
invokeMethod
(
final
bool
shouldShowRationale
=
await
_
methodC
hannel
.
invokeMethod
(
'shouldShowRequestPermissionRationale'
,
'shouldShowRequestPermissionRationale'
,
Codec
.
encodePermissionGroup
(
permission
));
Codec
.
encodePermissionGroup
(
permission
));
...
...
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