-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermission_handler_page.dart
executable file
·158 lines (147 loc) · 4.52 KB
/
permission_handler_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:worldfunclub/providers.dart';
import 'package:worldfunclub/vm/permission_handler_page_provider.dart';
class PermissionHandlerPage
extends ProviderWidget<PermissionHandlerPageProvider> {
PermissionHandlerPage() : super();
@override
Widget buildContent(BuildContext context,
PermissionHandlerPageProvider provider) {
return _PermissionHandlerPageContent(provider);
}
}
class _PermissionHandlerPageContent extends StatefulWidget {
final PermissionHandlerPageProvider provider;
_PermissionHandlerPageContent(this.provider);
@override
_PermissionHandlerPageContentState createState() =>
_PermissionHandlerPageContentState();
}
class _PermissionHandlerPageContentState
extends State<_PermissionHandlerPageContent> {
bool storageEnable = false;
bool locationEnable = false;
bool cameraEnable = false;
@override
void initState() {
super.initState();
Permission.camera.isGranted.then((value) {
setState(() {
cameraEnable = value;
});
});
Permission.location.isGranted.then((value) {
setState(() {
locationEnable = value;
});
});
Permission.storage.isGranted.then((value) {
setState(() {
storageEnable = value;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
title: Text("权限设置"),
brightness: Brightness.dark,
),
body: Column(
children: [
ListTile(
onTap: () {
if (!locationEnable) {
Permission.location.request().then((value) {
setState(() {
locationEnable = value.isGranted;
});
});
}
},
tileColor: Colors.white,
title: Text("允许途乐会获取地理信息"),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(locationEnable ? "已开启" : "点我开启"),
Icon(Icons.navigate_next)
],
),
),
ListTile(
tileColor: Colors.grey[100],
title: Text(
"方便您在需要定位业务下的定位。关于《位置信息》",
style: TextStyle(fontSize: 12.sp, color: Colors.black26),
),
),
ListTile(
onTap: () {
if (!cameraEnable) {
Permission.camera.request().then((value) {
setState(() {
cameraEnable = value.isGranted;
});
});
}
},
tileColor: Colors.white,
title: Text("允许途乐会访问相机"),
trailing:
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(cameraEnable ? "已开启" : "点我开启"),
Icon(Icons.navigate_next)
],
),
),
ListTile(
tileColor: Colors.grey[100],
title: Text(
"实现您购物拍摄用户评价。关于《访问相机》",
style: TextStyle(fontSize: 12.sp, color: Colors.black26),
),
),
ListTile(
onTap: () {
if (!storageEnable) {
Permission.storage.request().then((value) {
setState(() {
storageEnable = value.isGranted;
});
});
}
},
tileColor: Colors.white,
title: Text("允许途乐会访问相册"),
trailing:
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(storageEnable ? "已开启" : "点我开启"),
Icon(Icons.navigate_next)
],
),
),
ListTile(
tileColor: Colors.grey[100],
title: Text(
"实现您图片/视频的取用与上传。关于《访问相册》",
style: TextStyle(fontSize: 12.sp, color: Colors.black26),
),
),
ListTile(
tileColor: Colors.white,
title: Text("《隐私权政策》"),
),
],
),
);
}
}