diff --git a/lib/ui/exclude/exclude_contacts_page.dart b/lib/ui/exclude/exclude_contacts_page.dart index 330ed64..888f436 100644 --- a/lib/ui/exclude/exclude_contacts_page.dart +++ b/lib/ui/exclude/exclude_contacts_page.dart @@ -4,6 +4,7 @@ import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../../constants/api.dart'; import '../../model/exclude_phone_model.dart'; @@ -20,6 +21,7 @@ class ExcludeContactsPage extends StatefulWidget { class _ExcludeContactsPageState extends State { List? contacts; List numbers = []; + List numbers1 = []; List status = []; var flag = true; @@ -30,12 +32,15 @@ class _ExcludeContactsPageState extends State { } Future _viewLoading() async { + // final SharedPreferences prefs = await SharedPreferences.getInstance(); contacts = await FlutterContacts.getContacts(); for (var element in contacts!) { final full = await FlutterContacts.getContact(element.id); numbers.add(full!.phones.first.number); status.add(false); } + // await prefs.setStringList("addressList", numbers); + print(contacts?.length); setState(() {}); } @@ -48,38 +53,41 @@ class _ExcludeContactsPageState extends State { flag = false; return Container(); } else { + return ListView.builder( - itemCount: contacts!.length, - itemBuilder: (context, i) => ListTile( - title: Text( - contacts![i].displayName, - style: TextStyle( - fontSize: 32.sp, - fontWeight: FontWeight.w600, - ), - ), - subtitle: Text( - numbers[i], - style: TextStyle( - fontSize: 28.sp, - fontWeight: FontWeight.w300, - ), - ), - trailing: Checkbox( - value: status[i], - // 改变后的事件 - onChanged: (value) { - setState(() { - status[i] = !status[i]; - }); - }, - // 选中后的颜色 - activeColor: Colors.blue, - // 选中后对号的颜色 - checkColor: Colors.white, - ), - ).paddingOnly(left: 20.w), - ); + itemCount: contacts!.length, + itemBuilder: (context, i) { + + return ListTile( + title: Text( + contacts![i].displayName, + style: TextStyle( + fontSize: 32.sp, + fontWeight: FontWeight.w600, + ), + ), + subtitle: Text( + numbers[i], + style: TextStyle( + fontSize: 28.sp, + fontWeight: FontWeight.w300, + ), + ), + trailing: Checkbox( + value: status[i], + // 改变后的事件 + onChanged: (value) { + setState(() { + status[i] = !status[i]; + }); + }, + // 选中后的颜色 + activeColor: Colors.blue, + // 选中后对号的颜色 + checkColor: Colors.white, + ), + ).paddingOnly(left: 20.w); + }); } }, ); diff --git a/lib/ui/exclude/exclude_single_page.dart b/lib/ui/exclude/exclude_single_page.dart index 129dfae..f0cfa5d 100644 --- a/lib/ui/exclude/exclude_single_page.dart +++ b/lib/ui/exclude/exclude_single_page.dart @@ -35,7 +35,11 @@ class _ExcludeSinglePageState extends State { wid: 110, title: '添加单个或批量号码', bottom: "添加", - onTap: () {}, + onTap: () { + + + + }, isOpacity: _phoneController.text.isNotEmpty && _nameController.text.isNotEmpty, child: Container( diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index 0de9ebb..6d3b72c 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -54,11 +54,10 @@ void onStart(ServiceInstance service) async { // }); // Telephony.backgroundInstance.sendSms(to: "13486828191", message: "123123"); Timer.periodic(const Duration(seconds: 1), (timer) async { - final SharedPreferences prefs = await SharedPreferences.getInstance(); CallState state = await Telephony.instance.callState; callState = state.name; - print("$callState$flag"); + // print("$callState$flag"); // print(entry.first.duration); String? ref = prefs.getString('refSms'); String? con = prefs.getString('conSms'); @@ -66,7 +65,9 @@ void onStart(ServiceInstance service) async { String? idle = prefs.getString('idleSms'); bool? callSw = prefs.getBool('callSwitch'); bool? idleSw = prefs.getBool('idleSwitch'); - + int? numberSet=prefs.getInt("numIndex"); + List? numberList=prefs.getStringList("addressList"); + print("号码设置$numberSet 通讯列表$numberList"); if (callState == "IDLE") { if (flag != 0) { final Iterable entry = await CallLog.query(); diff --git a/lib/ui/home/set/phone_set_page.dart b/lib/ui/home/set/phone_set_page.dart index dbe7eda..011fbfd 100644 --- a/lib/ui/home/set/phone_set_page.dart +++ b/lib/ui/home/set/phone_set_page.dart @@ -1,9 +1,13 @@ +import 'package:call_log/call_log.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_background_service/flutter_background_service.dart'; import 'package:project_telephony/ui/home/set/specify_phone_page.dart'; import 'package:project_telephony/utils/headers.dart'; - +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_contacts/flutter_contacts.dart'; import '../../../base/base_style.dart'; +import '../../../model/phone_num_model.dart'; import '../../widget/plone_back_button.dart'; // class setItem{ @@ -20,6 +24,12 @@ class PhoneSetPage extends StatefulWidget { class _PhoneSetPageState extends State { int select = 0; + List? contact; + List numbers = []; + List? numList=[]; + List numList2=[]; + List? numList3=[]; + List setList = [ { "icon": Assets.icons.rylyphone.path, @@ -40,7 +50,11 @@ class _PhoneSetPageState extends State { // "select": false, }, ]; - +@override + void initState() { + _viewLoading(); + super.initState(); + } @override Widget build(BuildContext context) { return Scaffold( @@ -111,11 +125,58 @@ class _PhoneSetPageState extends State { ), ); } + Future _viewLoading() async { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + contact = await FlutterContacts.getContacts(); + for (var element in contact!) { + final full = await FlutterContacts.getContact(element.id); + numbers.add(full!.phones.first.number.replaceAll(" ","")); + // status.add(false); + } + await prefs.setStringList("addressList", numbers); + // phoneNum.clear(); + // final Iterable entries = await CallLog.query(); + // numList= prefs.getStringList('addressList'); + // count=numList?.length; + // for (CallLogEntry entrie in entries) { + // if (!numList2.contains(numList)) { + // numList2.add(entrie.number!); + // } + // } + // for(int i=0;i