@@ -5,24 +5,32 @@ import 'package:flutter/material.dart';
55import 'package:permission_handler/permission_handler.dart' ;
66
77void main () {
8- runApp (BaseflowPluginExample (
8+ runApp (
9+ BaseflowPluginExample (
910 pluginName: 'Permission Handler' ,
1011 githubURL: 'https://github.com/Baseflow/flutter-permission-handler' ,
1112 pubDevURL: 'https://pub.dev/packages/permission_handler' ,
12- pages: [PermissionHandlerWidget .createPage ()]));
13+ pages: [PermissionHandlerWidget .createPage ()],
14+ ),
15+ );
1316}
1417
1518///Defines the main theme color
1619final MaterialColor themeMaterialColor =
1720 BaseflowPluginExample .createMaterialColor (
18- const Color .fromRGBO (48 , 49 , 60 , 1 ));
21+ const Color .fromRGBO (48 , 49 , 60 , 1 ),
22+ );
1923
2024/// A Flutter application demonstrating the functionality of this plugin
2125class PermissionHandlerWidget extends StatefulWidget {
26+ const PermissionHandlerWidget ._();
27+
2228 /// Create a page containing the functionality of this plugin
2329 static ExamplePage createPage () {
2430 return ExamplePage (
25- Icons .location_on, (context) => PermissionHandlerWidget ());
31+ Icons .location_on,
32+ (context) => const PermissionHandlerWidget ._(),
33+ );
2634 }
2735
2836 @override
@@ -35,59 +43,61 @@ class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> {
3543 Widget build (BuildContext context) {
3644 return Center (
3745 child: ListView (
38- children: Permission .values
39- .where ((permission) {
40- if (Platform .isIOS) {
41- return permission != Permission .unknown &&
42- permission != Permission .phone &&
43- permission != Permission .sms &&
44- permission != Permission .ignoreBatteryOptimizations &&
45- permission != Permission .accessMediaLocation &&
46- permission != Permission .activityRecognition &&
47- permission != Permission .manageExternalStorage &&
48- permission != Permission .systemAlertWindow &&
49- permission != Permission .requestInstallPackages &&
50- permission != Permission .accessNotificationPolicy &&
51- permission != Permission .bluetoothScan &&
52- permission != Permission .bluetoothAdvertise &&
53- permission != Permission .bluetoothConnect &&
54- permission != Permission .nearbyWifiDevices &&
55- permission != Permission .videos &&
56- permission != Permission .audio &&
57- permission != Permission .scheduleExactAlarm &&
58- permission != Permission .sensorsAlways;
59- } else {
60- return permission != Permission .unknown &&
61- permission != Permission .mediaLibrary &&
62- permission != Permission .photosAddOnly &&
63- permission != Permission .reminders &&
64- permission != Permission .bluetooth &&
65- permission != Permission .appTrackingTransparency &&
66- permission != Permission .criticalAlerts &&
67- permission != Permission .assistant;
68- }
69- })
70- .map ((permission) => PermissionWidget (permission))
71- .toList ()),
46+ children:
47+ Permission .values
48+ .where ((permission) {
49+ if (Platform .isIOS) {
50+ return permission != Permission .unknown &&
51+ permission != Permission .phone &&
52+ permission != Permission .sms &&
53+ permission != Permission .ignoreBatteryOptimizations &&
54+ permission != Permission .accessMediaLocation &&
55+ permission != Permission .activityRecognition &&
56+ permission != Permission .manageExternalStorage &&
57+ permission != Permission .systemAlertWindow &&
58+ permission != Permission .requestInstallPackages &&
59+ permission != Permission .accessNotificationPolicy &&
60+ permission != Permission .bluetoothScan &&
61+ permission != Permission .bluetoothAdvertise &&
62+ permission != Permission .bluetoothConnect &&
63+ permission != Permission .nearbyWifiDevices &&
64+ permission != Permission .videos &&
65+ permission != Permission .audio &&
66+ permission != Permission .scheduleExactAlarm &&
67+ permission != Permission .sensorsAlways;
68+ } else {
69+ return permission != Permission .unknown &&
70+ permission != Permission .mediaLibrary &&
71+ permission != Permission .photosAddOnly &&
72+ permission != Permission .reminders &&
73+ permission != Permission .bluetooth &&
74+ permission != Permission .appTrackingTransparency &&
75+ permission != Permission .criticalAlerts &&
76+ permission != Permission .assistant;
77+ }
78+ })
79+ .map ((permission) => PermissionWidget (permission))
80+ .toList (),
81+ ),
7282 );
7383 }
7484}
7585
7686/// Permission widget containing information about the passed [Permission]
7787class PermissionWidget extends StatefulWidget {
7888 /// Constructs a [PermissionWidget] for the supplied [Permission]
79- const PermissionWidget (this ._permission );
89+ const PermissionWidget (this .permission, { super .key} );
8090
81- final Permission _permission;
91+ /// The [Permission] for which this widget is rendered.
92+ final Permission permission;
8293
8394 @override
84- _PermissionState createState () => _PermissionState (_permission );
95+ _PermissionState createState () => _PermissionState ();
8596}
8697
8798class _PermissionState extends State <PermissionWidget > {
88- _PermissionState (this ._permission );
99+ _PermissionState ();
89100
90- final Permission _permission;
91101 PermissionStatus _permissionStatus = PermissionStatus .denied;
92102
93103 @override
@@ -98,7 +108,7 @@ class _PermissionState extends State<PermissionWidget> {
98108 }
99109
100110 void _listenForPermissionStatus () async {
101- final status = await _permission .status;
111+ final status = await widget.permission .status;
102112 setState (() => _permissionStatus = status);
103113 }
104114
@@ -119,44 +129,45 @@ class _PermissionState extends State<PermissionWidget> {
119129 Widget build (BuildContext context) {
120130 return ListTile (
121131 title: Text (
122- _permission .toString (),
132+ widget.permission .toString (),
123133 style: Theme .of (context).textTheme.bodyLarge,
124134 ),
125135 subtitle: Text (
126136 _permissionStatus.toString (),
127137 style: TextStyle (color: getPermissionColor ()),
128138 ),
129- trailing: (_permission is PermissionWithService )
130- ? IconButton (
131- icon: const Icon (
132- Icons .info,
133- color: Colors .white,
134- ),
135- onPressed: () {
136- checkServiceStatus (
137- context, _permission as PermissionWithService );
138- })
139- : null ,
139+ trailing:
140+ (widget.permission is PermissionWithService )
141+ ? IconButton (
142+ icon: const Icon (Icons .info, color: Colors .white),
143+ onPressed: () {
144+ checkServiceStatus (
145+ context,
146+ widget.permission as PermissionWithService ,
147+ );
148+ },
149+ )
150+ : null ,
140151 onTap: () {
141- requestPermission (_permission );
152+ requestPermission (widget.permission );
142153 },
143154 );
144155 }
145156
146157 void checkServiceStatus (
147- BuildContext context, PermissionWithService permission) async {
148- ScaffoldMessenger .of (context).showSnackBar (SnackBar (
149- content: Text ((await permission.serviceStatus).toString ()),
150- ));
158+ BuildContext context,
159+ PermissionWithService permission,
160+ ) async {
161+ ScaffoldMessenger .of (context).showSnackBar (
162+ SnackBar (content: Text ((await permission.serviceStatus).toString ())),
163+ );
151164 }
152165
153166 Future <void > requestPermission (Permission permission) async {
154167 final status = await permission.request ();
155168
156169 setState (() {
157- print (status);
158170 _permissionStatus = status;
159- print (_permissionStatus);
160171 });
161172 }
162173}
0 commit comments