判断通讯录权限是否打开

master
戴余标 2 years ago
parent 300caf7f27
commit 61e62e1e62

@ -1,11 +1,8 @@
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_utils/get_utils.dart';
import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart';
class ExcludeContactsPage extends StatefulWidget {
@ -16,20 +13,21 @@ class ExcludeContactsPage extends StatefulWidget {
}
class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
late List<Contact> contacts;
List<Contact>? contacts;
List<String> numbers = [];
List<bool> status = [];
var flag = true;
bool _permissionDenied = false;
@override
void initState() {
super.initState();
_incrementCounter();
_viewLoading();
}
Future _incrementCounter() async {
Future _viewLoading() async {
contacts = await FlutterContacts.getContacts();
for (var element in contacts) {
for (var element in contacts!) {
final full = await FlutterContacts.getContact(element.id);
numbers.add(full!.phones.first.number);
status.add(false);
@ -40,17 +38,17 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
@override
Widget build(BuildContext context) {
var profileBuilder = FutureBuilder(
future: _incrementCounter(),
future: _viewLoading(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting && flag) {
flag = false;
return Container();
} else {
return ListView.builder(
itemCount: contacts.length,
itemCount: contacts!.length,
itemBuilder: (context, i) => ListTile(
title: Text(
contacts[i].displayName,
contacts![i].displayName,
style: TextStyle(
fontSize: 32.sp,
fontWeight: FontWeight.w600,
@ -86,11 +84,11 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
title: "从通讯录添加",
bottom: "添加",
onTap: () {
if(status.contains(true)){
if (status.contains(true)) {
// BotToast.showText(text: "");
Get.back();
}else{
} else {
BotToast.showText(text: "还未选中手机号");
}
},

@ -2,6 +2,7 @@ import 'package:call_log/call_log.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:project_telephony/ui/exclude/exclude_contacts_page.dart';
import 'package:project_telephony/ui/exclude/exclude_single_page.dart';
import 'package:project_telephony/ui/home/home_page.dart';
@ -13,6 +14,7 @@ import '../../../base/base_style.dart';
import '../../../model/phone_num_model.dart';
import '../../widget/centertipsalterwidget.dart';
import '../../widget/scaffold_theme_widget.dart';
class SpecifyPhonePage extends StatefulWidget {
@ -63,8 +65,24 @@ class _SpecifyPhonePageState extends State<SpecifyPhonePage> {
onTap: () {},
child: const CallRecordsList()));
}),
_getAddPhone("通迅录添加", "通过本机通讯录添加号码", () {
Get.to(() => (const ExcludeContactsPage()));
_getAddPhone("通迅录添加", "通过本机通讯录添加号码", () async {
if(await Permission.contacts.isDenied){
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: const Text('获取通讯录权限还未开启'),
actions: [
ElevatedButton(onPressed: (){
openAppSettings();
},
child: const Text("前往开启"),),
],
);
});
}else{
Get.to(() => (const ExcludeContactsPage()));
}
}),
_getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () {
Get.to(() => (const ExcludeSinglePage()));
@ -105,155 +123,6 @@ class _SpecifyPhonePageState extends State<SpecifyPhonePage> {
],
)),
);
// PloneBottom(
// onTap: () {
// showModalBottomSheet(
// builder: (BuildContext context) {
// return Container(
// width: double.infinity,
// height: 750.w,
// padding: EdgeInsets.symmetric(horizontal: 32.w),
// child: Column(
// children: [
// 48.hb,
// Text(
// "添加号码",
// style: TextStyle(
// fontSize: 34.w,
// fontWeight: FontWeight.bold),
// ),
// Expanded(
// child: ListView(
// children: [
// _getAddPhone("通话记录添加", "通过本机通话记录添加号码", () {
// Get.to(() => ScaffoldThemeWidget(
// bottom: '添加',
// title: '从通话记录添加',
// isBorder: true,
// isOpacity: false,
// onTap: () { },
// child: CallRecordsList()
// ));
// }),
// _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () {
// Get.to(() => (const ExcludeContactsPage()));
// }),
// _getAddPhone(
// "添加单个或批量号码", "通过输入号码段添加批量号码", () {}),
// ],
// )),
// PloneBottom(
// onTap: () {
// Navigator.pop(context);
// },
// hPadding: 32,
// border: true,
// textColor: const Color(0xFF1890FF),
// color2: const Color(0xFFF9F9F9),
// color1: const Color(0xFFF9F9F9),
// text: "取消",
// ),
// 32.hb
// ],
// ),
// );
// },
// context: context);
// },
// border: true,
// color2: const Color(0xFF74BCFF),
// color1: const Color(0xFF1890FF),
// text: "添加",
// ),
// Scaffold(
// appBar: AppBar(
// elevation: 0,
// title: Text(
// '发送号码设置',
// style: TextStyle(
// fontSize: BaseStyle.fontSize34,
// color: BaseStyle.color333333,
// fontWeight: FontWeight.bold),
// ),
// titleSpacing: 162.w,
// leading: const CloudBackButton(isSpecial: true),
// backgroundColor: kForeGroundColor),
// backgroundColor: kForeGroundColor,
// body: EasyRefresh(
// firstRefresh: true,
// controller: _refreshController,
// header: MaterialHeader(),
// // footer: MaterialFooter(),
// onRefresh: () async {
// // await userProvider.updateUserInfo();
//
// setState(() {});
// },
// child: ListView(
// children: [
// _getNullList(),
// PloneBottom(
// onTap: () {
// showModalBottomSheet(
// builder: (BuildContext context) {
// return Container(
// width: double.infinity,
// height: 750.w,
// padding: EdgeInsets.symmetric(horizontal: 32.w),
// child: Column(
// children: [
// 48.hb,
// Text(
// "添加号码",
// style: TextStyle(
// fontSize: 34.w,
// fontWeight: FontWeight.bold),
// ),
// Expanded(
// child: ListView(
// children: [
// _getAddPhone("通话记录添加", "通过本机通话记录添加号码", () {
// Get.to(() => const ScaffoldThemeWidget(
// bottom: '添加',
// title: '从通话记录添加',
// isBorder: true,
// isOpacity: false,
// child: CallRecordsList()
// ));
// }),
// _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () {
// Get.to(() => (const ExcludeContactsPage()));
// }),
// _getAddPhone(
// "添加单个或批量号码", "通过输入号码段添加批量号码", () {}),
// ],
// )),
// PloneBottom(
// onTap: () {
// Navigator.pop(context);
// },
// hPadding: 32,
// border: true,
// textColor: const Color(0xFF1890FF),
// color2: const Color(0xFFF9F9F9),
// color1: const Color(0xFFF9F9F9),
// text: "取消",
// ),
// 32.hb
// ],
// ),
// );
// },
// context: context);
// },
// border: true,
// color2: const Color(0xFF74BCFF),
// color1: const Color(0xFF1890FF),
// text: "添加",
// ),
// ],
// )),
// );
}
_getAddPhone(String title, String text, VoidCallback widget) {

@ -74,12 +74,7 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
bottomNavigationBar: GestureDetector(
onTap: () async {
await _launchUrl();
// await launchUrlString("tel:13111111111");
},
// onTap: () async{
//
// },
child: Container(
margin: EdgeInsets.symmetric(horizontal: 64.w, vertical: 24.w),
padding: EdgeInsets.symmetric(horizontal: 214.w, vertical: 26.w),
@ -95,21 +90,6 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
);
}
// Color getPermissionColor() {
// if(true){
// return Colors.red;
// }else{
// return Colors.green;
// }
// }
// String getPermissionStu() {
// if (false) {
// return "未允许";
// } else {
// return "已允许";
// }
// }
Future<void> _launchUrl() async {
if (!await launchUrl(_url)) {
throw 'Could not launch $_url';
@ -123,23 +103,6 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
openAppSettings();
setState(() {});
}
// if(!(sms && plone)){
// // print(sms);
// // print(plone);
// openAppSettings();
// }else{
// // print("123123123123");
// }
// await Permission.phone.request();
// await Permission.sms.request();
// Map<Permission, PermissionStatus> statuses = await [
// Permission.sms,
// Permission.phone,
// ].request();
//
// openAppSettings();
// print(await Permission.phone.request().isGranted);
// print(await Permission.sms.request().isGranted);
},
title: Text(
name,

Loading…
Cancel
Save