You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project_telephony/lib/ui/user/privacy_rights_page.dart

122 lines
3.6 KiB

2 years ago
import 'package:flutter/material.dart';
2 years ago
import 'package:permission_handler/permission_handler.dart';
2 years ago
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/utils/headers.dart';
2 years ago
import 'package:url_launcher/url_launcher.dart';
2 years ago
2 years ago
class PrivacyRightsPage extends StatefulWidget {
final String name;
2 years ago
2 years ago
const PrivacyRightsPage({Key? key, required this.name}) : super(key: key);
@override
_PrivacyRightsPageState createState() => _PrivacyRightsPageState();
}
2 years ago
2 years ago
final Uri _url = Uri.parse('https://www.dxbs.vip//explain.html');
2 years ago
// final Telephony telephony = Telephony.instance;
2 years ago
// late final bool permissionsGranted;
// String body = "";
// @override
2 years ago
// void initState() async {
// initPlatformState();
2 years ago
// }
2 years ago
bool sms = false;
bool plone = false;
bool callLog = false;
2 years ago
bool contacts = false;
2 years ago
@override
class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
2 years ago
@override
void initState() {
super.initState();
2 years ago
Future.delayed(const Duration(seconds: 0), () async {
2 years ago
await _listenForPermissionStatus();
});
2 years ago
}
2 years ago
2 years ago
Future<void> _listenForPermissionStatus() async {
2 years ago
sms = await Permission.sms.request().isGranted;
plone = await Permission.phone.request().isGranted;
callLog = await Permission.callLog.request().isGranted;
2 years ago
contacts = await Permission.contacts.request().isGranted;
2 years ago
setState(() {});
2 years ago
}
2 years ago
2 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
2 years ago
appBar: AppBar(
elevation: 0,
title: Text(
widget.name,
style: TextStyle(
fontSize: BaseStyle.fontSize34,
color: BaseStyle.color333333,
fontWeight: FontWeight.bold),
),
titleSpacing: 162.w,
leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor),
backgroundColor: Colors.white,
2 years ago
body: Column(
children: [
_getRights("获取设备来电状态", "用于获取来电状态", plone),
_getRights("获取设备短信权限", "用于发送短信", sms),
_getRights("获取设备通话记录", "用于获取来电", callLog),
2 years ago
_getRights("获取设备通讯录", "用于插入排除手机号", contacts),
2 years ago
],
),
2 years ago
bottomNavigationBar: GestureDetector(
2 years ago
onTap: () async {
2 years ago
await _launchUrl();
2 years ago
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 64.w, vertical: 24.w),
padding: EdgeInsets.symmetric(horizontal: 214.w, vertical: 26.w),
decoration: BoxDecoration(
color: const Color(0xFFF9F9F9),
borderRadius: BorderRadius.circular(8.w)),
child: Text(
"查看使用说明",
style: TextStyle(color: const Color(0xFF1890FF), fontSize: 28.sp),
),
),
),
2 years ago
);
2 years ago
}
2 years ago
2 years ago
Future<void> _launchUrl() async {
if (!await launchUrl(_url)) {
throw 'Could not launch $_url';
}
}
2 years ago
_getRights(String name, String text, bool state) {
return ListTile(
onTap: () async {
if (!state) {
2 years ago
openAppSettings();
2 years ago
setState(() {});
2 years ago
}
2 years ago
},
2 years ago
title: Text(
2 years ago
name,
2 years ago
style: Theme.of(context).textTheme.titleMedium,
2 years ago
),
2 years ago
subtitle: Text(
text,
2 years ago
),
trailing: Wrap(
children: [
2 years ago
Text(state ? "已允许" : "未允许",
style: TextStyle(color: state ? Colors.green : Colors.red)),
2 years ago
const Icon(Icons.arrow_forward_ios),
],
),
2 years ago
);
2 years ago
}
2 years ago
}