|
|
@ -1,50 +1,44 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
|
|
|
|
|
|
|
|
import 'package:project_telephony/base/base_style.dart';
|
|
|
|
import 'package:project_telephony/base/base_style.dart';
|
|
|
|
|
|
|
|
// import 'package:project_telephony/main.dart';
|
|
|
|
import 'package:project_telephony/ui/widget/plone_back_button.dart';
|
|
|
|
import 'package:project_telephony/ui/widget/plone_back_button.dart';
|
|
|
|
|
|
|
|
import 'package:project_telephony/ui/widget/plone_bottom.dart';
|
|
|
|
import 'package:project_telephony/utils/headers.dart';
|
|
|
|
import 'package:project_telephony/utils/headers.dart';
|
|
|
|
import 'package:telephony/telephony.dart';
|
|
|
|
// import 'package:telephony/telephony.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class PrivacyRightsPage extends StatefulWidget {
|
|
|
|
class PrivacyRightsPage extends StatefulWidget {
|
|
|
|
final String name;
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
|
|
|
|
const PrivacyRightsPage({Key? key, required this.name}) : super(key: key);
|
|
|
|
const PrivacyRightsPage({Key? key, required this.name}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
_PrivacyRightsPageState createState() => _PrivacyRightsPageState();
|
|
|
|
_PrivacyRightsPageState createState() => _PrivacyRightsPageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final Telephony telephony = Telephony.instance;
|
|
|
|
// final Telephony telephony = Telephony.instance;
|
|
|
|
// late final bool permissionsGranted;
|
|
|
|
// late final bool permissionsGranted;
|
|
|
|
// String body = "";
|
|
|
|
// String body = "";
|
|
|
|
// @override
|
|
|
|
// @override
|
|
|
|
// void initState() async {
|
|
|
|
// initState() async {
|
|
|
|
// initPlatformState();
|
|
|
|
|
|
|
|
|
|
|
|
// // initPlatformState();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
bool? pd;
|
|
|
|
|
|
|
|
|
|
|
|
class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
|
|
|
|
class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
|
|
|
|
final Permission _permission = Permission.phone;
|
|
|
|
|
|
|
|
final PermissionHandlerPlatform _permissionHandler =
|
|
|
|
|
|
|
|
PermissionHandlerPlatform.instance;
|
|
|
|
|
|
|
|
PermissionStatus _permissionStatus = PermissionStatus.denied;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> requestPermission(Permission permission) async {
|
|
|
|
|
|
|
|
final status = await _permissionHandler.requestPermissions([permission]);
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
_permissionStatus = status[permission] ?? PermissionStatus.denied;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
|
|
|
|
Future.delayed(const Duration(seconds: 2), () async {
|
|
|
|
|
|
|
|
await _refresh();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
_listenForPermissionStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _listenForPermissionStatus() async {
|
|
|
|
_refresh() async {
|
|
|
|
final status = await _permissionHandler.checkPermissionStatus(_permission);
|
|
|
|
var status = await Permission.camera.status;
|
|
|
|
setState(() => _permissionStatus = status);
|
|
|
|
pd = status.isDenied;
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
@ -63,8 +57,13 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
|
|
|
|
leading: const CloudBackButton(isSpecial: true),
|
|
|
|
leading: const CloudBackButton(isSpecial: true),
|
|
|
|
backgroundColor: kForeGroundColor),
|
|
|
|
backgroundColor: kForeGroundColor),
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
body: widget.name == "隐私政策" ? null : _getRights(true),
|
|
|
|
body: widget.name == "隐私政策"
|
|
|
|
);
|
|
|
|
? null
|
|
|
|
|
|
|
|
: Column(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
_getRights(pd!),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// onMessage(SmsMessage message) async {
|
|
|
|
// onMessage(SmsMessage message) async {
|
|
|
@ -92,116 +91,68 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
_getRights(bool pd) {
|
|
|
|
_getRights(bool pd) {
|
|
|
|
return ListView(
|
|
|
|
return GestureDetector(
|
|
|
|
children: Permission.values
|
|
|
|
onTap: () {},
|
|
|
|
.where((permission) {
|
|
|
|
child: Container(
|
|
|
|
return permission == Permission.phone ||
|
|
|
|
height: 144.w,
|
|
|
|
permission == Permission.sms;
|
|
|
|
width: 750.w,
|
|
|
|
})
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 64.w, vertical: 17.w),
|
|
|
|
.map((permission) => PermissionWidget(permission))
|
|
|
|
child: Row(
|
|
|
|
.toList());
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
}
|
|
|
|
children: [
|
|
|
|
}
|
|
|
|
Column(
|
|
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
class PermissionWidget extends StatefulWidget {
|
|
|
|
|
|
|
|
const PermissionWidget(this._permission);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Permission _permission;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
_PermissionState createState() => _PermissionState(_permission);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _PermissionState extends State<PermissionWidget> {
|
|
|
|
|
|
|
|
_PermissionState(this._permission);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Permission _permission;
|
|
|
|
|
|
|
|
final PermissionHandlerPlatform _permissionHandler =
|
|
|
|
|
|
|
|
PermissionHandlerPlatform.instance;
|
|
|
|
|
|
|
|
PermissionStatus _permissionStatus = PermissionStatus.denied;
|
|
|
|
|
|
|
|
List<String> title = [
|
|
|
|
|
|
|
|
"获取来电权限",
|
|
|
|
|
|
|
|
"获取短信权限",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
List<String> sub = [
|
|
|
|
|
|
|
|
"用于监听来电状态",
|
|
|
|
|
|
|
|
"用于发送短信",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_listenForPermissionStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _listenForPermissionStatus() async {
|
|
|
|
|
|
|
|
final status = await _permissionHandler.checkPermissionStatus(_permission);
|
|
|
|
|
|
|
|
setState(() => _permissionStatus = status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Color getPermissionColor() {
|
|
|
|
|
|
|
|
switch (_permissionStatus) {
|
|
|
|
|
|
|
|
case PermissionStatus.denied:
|
|
|
|
|
|
|
|
return Colors.red;
|
|
|
|
|
|
|
|
case PermissionStatus.granted:
|
|
|
|
|
|
|
|
return Colors.green;
|
|
|
|
|
|
|
|
case PermissionStatus.limited:
|
|
|
|
|
|
|
|
return Colors.orange;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return Colors.grey;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getPermissionStu() {
|
|
|
|
|
|
|
|
switch (_permissionStatus) {
|
|
|
|
|
|
|
|
case PermissionStatus.denied:
|
|
|
|
|
|
|
|
return "未允许";
|
|
|
|
|
|
|
|
case PermissionStatus.granted:
|
|
|
|
|
|
|
|
return "已允许";
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return "未允许";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
|
|
return ListTile(
|
|
|
|
|
|
|
|
title: Text(
|
|
|
|
|
|
|
|
_permission.value==8?title[0]:title[1],
|
|
|
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
subtitle: Text(
|
|
|
|
|
|
|
|
_permission.value==8?sub[0]:sub[1],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
trailing: Wrap(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
Text(getPermissionStu(),
|
|
|
|
Text(
|
|
|
|
style: TextStyle(color: getPermissionColor())),
|
|
|
|
'获取设备来电',
|
|
|
|
const Icon(Icons.arrow_forward_ios),
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
|
|
fontSize: 32.sp,
|
|
|
|
|
|
|
|
color: BaseStyle.color333333,
|
|
|
|
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
16.hb,
|
|
|
|
|
|
|
|
Text('用于获取设备',
|
|
|
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
|
|
fontSize: 28.sp, color: BaseStyle.color999999)),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
269.wb,
|
|
|
|
requestPermission(_permission);
|
|
|
|
Text(pd ? "未允许" : "已允许",
|
|
|
|
},
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
|
|
fontSize: 24.sp,
|
|
|
|
|
|
|
|
color: pd
|
|
|
|
|
|
|
|
? const Color(0xFFFF4D4D)
|
|
|
|
|
|
|
|
: BaseStyle.color999999)),
|
|
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
|
|
width: 48.w,
|
|
|
|
|
|
|
|
height: 48.w,
|
|
|
|
|
|
|
|
child: const Icon(
|
|
|
|
|
|
|
|
Icons.keyboard_arrow_right,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void checkServiceStatus(
|
|
|
|
_getA() {
|
|
|
|
BuildContext context, PermissionWithService permission) async {
|
|
|
|
return PloneBottom(
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
onTap: () async {
|
|
|
|
content: Text(
|
|
|
|
var status = await Permission.camera.status;
|
|
|
|
(await _permissionHandler.checkServiceStatus(permission)).toString()),
|
|
|
|
if (status.isDenied) {
|
|
|
|
));
|
|
|
|
// openAppSettings();//返回后台
|
|
|
|
|
|
|
|
// print(status.isDenied);
|
|
|
|
|
|
|
|
// print("已允许");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
print("未允许");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
Future<void> requestPermission(Permission permission) async {
|
|
|
|
);
|
|
|
|
final status = await _permissionHandler.requestPermissions([permission]);
|
|
|
|
// var status = await Permission.camera.status;
|
|
|
|
|
|
|
|
// if (status.isDenied) {
|
|
|
|
setState(() {
|
|
|
|
// return Text("已允许");
|
|
|
|
print(status);
|
|
|
|
// } else {
|
|
|
|
_permissionStatus = status[permission] ?? PermissionStatus.denied;
|
|
|
|
// return Text("未允许");
|
|
|
|
print(_permissionStatus);
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|