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
17e196ad
Commit
17e196ad
authored
Mar 08, 2020
by
Marcel Garus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example app to use new api
parent
aabf2df6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
50 deletions
+35
-50
permission_handler/example/lib/main.dart
+35
-50
No files found.
permission_handler/example/lib/main.dart
View file @
17e196ad
...
@@ -17,33 +17,31 @@ class MyApp extends StatelessWidget {
...
@@ -17,33 +17,31 @@ class MyApp extends StatelessWidget {
actions:
<
Widget
>[
actions:
<
Widget
>[
IconButton
(
IconButton
(
icon:
const
Icon
(
Icons
.
settings
),
icon:
const
Icon
(
Icons
.
settings
),
onPressed:
()
{
onPressed:
()
async
{
PermissionHandler
().
openAppSettings
().
then
((
bool
hasOpened
)
=>
var
hasOpened
=
openAppSettings
();
debugPrint
(
'App Settings opened: '
+
hasOpened
.
toString
()
));
debugPrint
(
'App Settings opened: '
+
hasOpened
.
toString
(
));
},
},
)
)
],
],
),
),
body:
Center
(
body:
Center
(
child:
ListView
(
child:
ListView
(
children:
Permission
Group
.
values
children:
Permission
.
values
.
where
((
Permission
Group
permission
)
{
.
where
((
Permission
permission
)
{
if
(
Platform
.
isIOS
)
{
if
(
Platform
.
isIOS
)
{
return
permission
!=
PermissionGroup
.
unknown
&&
return
permission
!=
Permission
.
unknown
&&
permission
!=
PermissionGroup
.
sms
&&
permission
!=
Permission
.
sms
&&
permission
!=
PermissionGroup
.
storage
&&
permission
!=
Permission
.
storage
&&
permission
!=
permission
!=
Permission
.
ignoreBatteryOptimizations
&&
PermissionGroup
.
ignoreBatteryOptimizations
&&
permission
!=
Permission
.
accessMediaLocation
;
permission
!=
PermissionGroup
.
accessMediaLocation
;
}
else
{
}
else
{
return
permission
!=
Permission
Group
.
unknown
&&
return
permission
!=
Permission
.
unknown
&&
permission
!=
Permission
Group
.
mediaLibrary
&&
permission
!=
Permission
.
mediaLibrary
&&
permission
!=
Permission
Group
.
photos
&&
permission
!=
Permission
.
photos
&&
permission
!=
Permission
Group
.
reminders
;
permission
!=
Permission
.
reminders
;
}
}
})
})
.
map
((
PermissionGroup
permission
)
=>
.
map
((
permission
)
=>
PermissionWidget
(
permission
))
PermissionWidget
(
permission
))
.
toList
()),
.
toList
()),
),
),
),
),
...
@@ -54,19 +52,19 @@ class MyApp extends StatelessWidget {
...
@@ -54,19 +52,19 @@ class MyApp extends StatelessWidget {
/// Permission widget which displays a permission and allows users to request
/// Permission widget which displays a permission and allows users to request
/// the permissions.
/// the permissions.
class
PermissionWidget
extends
StatefulWidget
{
class
PermissionWidget
extends
StatefulWidget
{
/// Constructs a [PermissionWidget] for the supplied [Permission
Group
].
/// Constructs a [PermissionWidget] for the supplied [Permission].
const
PermissionWidget
(
this
.
_permission
Group
);
const
PermissionWidget
(
this
.
_permission
);
final
Permission
Group
_permissionGroup
;
final
Permission
_permission
;
@override
@override
_PermissionState
createState
()
=>
_PermissionState
(
_permission
Group
);
_PermissionState
createState
()
=>
_PermissionState
(
_permission
);
}
}
class
_PermissionState
extends
State
<
PermissionWidget
>
{
class
_PermissionState
extends
State
<
PermissionWidget
>
{
_PermissionState
(
this
.
_permission
Group
);
_PermissionState
(
this
.
_permission
);
final
Permission
Group
_permissionGroup
;
final
Permission
_permission
;
PermissionStatus
_permissionStatus
=
PermissionStatus
.
unknown
;
PermissionStatus
_permissionStatus
=
PermissionStatus
.
unknown
;
@override
@override
...
@@ -76,15 +74,9 @@ class _PermissionState extends State<PermissionWidget> {
...
@@ -76,15 +74,9 @@ class _PermissionState extends State<PermissionWidget> {
_listenForPermissionStatus
();
_listenForPermissionStatus
();
}
}
void
_listenForPermissionStatus
()
{
void
_listenForPermissionStatus
()
async
{
final
Future
<
PermissionStatus
>
statusFuture
=
final
status
=
await
_permission
.
status
;
PermissionHandler
().
checkPermissionStatus
(
_permissionGroup
);
setState
(()
=>
_permissionStatus
=
status
);
statusFuture
.
then
((
PermissionStatus
status
)
{
setState
(()
{
_permissionStatus
=
status
;
});
});
}
}
Color
getPermissionColor
()
{
Color
getPermissionColor
()
{
...
@@ -101,7 +93,7 @@ class _PermissionState extends State<PermissionWidget> {
...
@@ -101,7 +93,7 @@ class _PermissionState extends State<PermissionWidget> {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
ListTile
(
return
ListTile
(
title:
Text
(
_permission
Group
.
toString
()),
title:
Text
(
_permission
.
toString
()),
subtitle:
Text
(
subtitle:
Text
(
_permissionStatus
.
toString
(),
_permissionStatus
.
toString
(),
style:
TextStyle
(
color:
getPermissionColor
()),
style:
TextStyle
(
color:
getPermissionColor
()),
...
@@ -109,33 +101,26 @@ class _PermissionState extends State<PermissionWidget> {
...
@@ -109,33 +101,26 @@ class _PermissionState extends State<PermissionWidget> {
trailing:
IconButton
(
trailing:
IconButton
(
icon:
const
Icon
(
Icons
.
info
),
icon:
const
Icon
(
Icons
.
info
),
onPressed:
()
{
onPressed:
()
{
checkServiceStatus
(
context
,
_permission
Group
);
checkServiceStatus
(
context
,
_permission
);
}),
}),
onTap:
()
{
onTap:
()
{
requestPermission
(
_permission
Group
);
requestPermission
(
_permission
);
},
},
);
);
}
}
void
checkServiceStatus
(
BuildContext
context
,
PermissionGroup
permission
)
{
void
checkServiceStatus
(
BuildContext
context
,
Permission
permission
)
async
{
PermissionHandler
()
Scaffold
.
of
(
context
).
showSnackBar
(
SnackBar
(
.
checkServiceStatus
(
permission
)
content:
Text
((
await
permission
.
status
).
toString
()),
.
then
((
ServiceStatus
serviceStatus
)
{
));
final
SnackBar
snackBar
=
SnackBar
(
content:
Text
(
serviceStatus
.
toString
()));
Scaffold
.
of
(
context
).
showSnackBar
(
snackBar
);
});
}
}
Future
<
void
>
requestPermission
(
PermissionGroup
permission
)
async
{
Future
<
void
>
requestPermission
(
Permission
permission
)
async
{
final
List
<
PermissionGroup
>
permissions
=
<
PermissionGroup
>[
permission
];
final
status
=
await
permission
.
request
();
final
Map
<
PermissionGroup
,
PermissionStatus
>
permissionRequestResult
=
await
PermissionHandler
().
requestPermissions
(
permissions
);
setState
(()
{
setState
(()
{
print
(
permissionRequestResult
);
print
(
status
);
_permissionStatus
=
permissionRequestResult
[
permission
]
;
_permissionStatus
=
status
;
print
(
_permissionStatus
);
print
(
_permissionStatus
);
});
});
}
}
...
...
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