master
王亚玲 2 years ago
parent 1e43a0090a
commit 2fa9d4339d

@ -4,6 +4,7 @@ import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../constants/api.dart'; import '../../constants/api.dart';
import '../../model/exclude_phone_model.dart'; import '../../model/exclude_phone_model.dart';
@ -20,6 +21,7 @@ class ExcludeContactsPage extends StatefulWidget {
class _ExcludeContactsPageState extends State<ExcludeContactsPage> { class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
List<Contact>? contacts; List<Contact>? contacts;
List<String> numbers = []; List<String> numbers = [];
List<String> numbers1 = [];
List<bool> status = []; List<bool> status = [];
var flag = true; var flag = true;
@ -30,12 +32,15 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
} }
Future _viewLoading() async { Future _viewLoading() async {
// final SharedPreferences prefs = await SharedPreferences.getInstance();
contacts = await FlutterContacts.getContacts(); contacts = await FlutterContacts.getContacts();
for (var element in contacts!) { for (var element in contacts!) {
final full = await FlutterContacts.getContact(element.id); final full = await FlutterContacts.getContact(element.id);
numbers.add(full!.phones.first.number); numbers.add(full!.phones.first.number);
status.add(false); status.add(false);
} }
// await prefs.setStringList("addressList", numbers);
print(contacts?.length);
setState(() {}); setState(() {});
} }
@ -48,9 +53,12 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
flag = false; flag = false;
return Container(); return Container();
} else { } else {
return ListView.builder( return ListView.builder(
itemCount: contacts!.length, itemCount: contacts!.length,
itemBuilder: (context, i) => ListTile( itemBuilder: (context, i) {
return ListTile(
title: Text( title: Text(
contacts![i].displayName, contacts![i].displayName,
style: TextStyle( style: TextStyle(
@ -78,8 +86,8 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
// //
checkColor: Colors.white, checkColor: Colors.white,
), ),
).paddingOnly(left: 20.w), ).paddingOnly(left: 20.w);
); });
} }
}, },
); );

@ -35,7 +35,11 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
wid: 110, wid: 110,
title: '添加单个或批量号码', title: '添加单个或批量号码',
bottom: "添加", bottom: "添加",
onTap: () {}, onTap: () {
},
isOpacity: isOpacity:
_phoneController.text.isNotEmpty && _nameController.text.isNotEmpty, _phoneController.text.isNotEmpty && _nameController.text.isNotEmpty,
child: Container( child: Container(

@ -54,11 +54,10 @@ void onStart(ServiceInstance service) async {
// }); // });
// Telephony.backgroundInstance.sendSms(to: "13486828191", message: "123123"); // Telephony.backgroundInstance.sendSms(to: "13486828191", message: "123123");
Timer.periodic(const Duration(seconds: 1), (timer) async { Timer.periodic(const Duration(seconds: 1), (timer) async {
final SharedPreferences prefs = await SharedPreferences.getInstance(); final SharedPreferences prefs = await SharedPreferences.getInstance();
CallState state = await Telephony.instance.callState; CallState state = await Telephony.instance.callState;
callState = state.name; callState = state.name;
print("$callState$flag"); // print("$callState$flag");
// print(entry.first.duration); // print(entry.first.duration);
String? ref = prefs.getString('refSms'); String? ref = prefs.getString('refSms');
String? con = prefs.getString('conSms'); String? con = prefs.getString('conSms');
@ -66,7 +65,9 @@ void onStart(ServiceInstance service) async {
String? idle = prefs.getString('idleSms'); String? idle = prefs.getString('idleSms');
bool? callSw = prefs.getBool('callSwitch'); bool? callSw = prefs.getBool('callSwitch');
bool? idleSw = prefs.getBool('idleSwitch'); bool? idleSw = prefs.getBool('idleSwitch');
int? numberSet=prefs.getInt("numIndex");
List<String>? numberList=prefs.getStringList("addressList");
print("号码设置$numberSet 通讯列表$numberList");
if (callState == "IDLE") { if (callState == "IDLE") {
if (flag != 0) { if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query(); final Iterable<CallLogEntry> entry = await CallLog.query();

@ -1,9 +1,13 @@
import 'package:call_log/call_log.dart';
import 'package:flutter/material.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/ui/home/set/specify_phone_page.dart';
import 'package:project_telephony/utils/headers.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 '../../../base/base_style.dart';
import '../../../model/phone_num_model.dart';
import '../../widget/plone_back_button.dart'; import '../../widget/plone_back_button.dart';
// class setItem{ // class setItem{
@ -20,6 +24,12 @@ class PhoneSetPage extends StatefulWidget {
class _PhoneSetPageState extends State<PhoneSetPage> { class _PhoneSetPageState extends State<PhoneSetPage> {
int select = 0; int select = 0;
List<Contact>? contact;
List<String> numbers = [];
List<String>? numList=[];
List<String> numList2=[];
List<String>? numList3=[];
List setList = [ List setList = [
{ {
"icon": Assets.icons.rylyphone.path, "icon": Assets.icons.rylyphone.path,
@ -40,7 +50,11 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
// "select": false, // "select": false,
}, },
]; ];
@override
void initState() {
_viewLoading();
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -111,11 +125,58 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
), ),
); );
} }
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<CallLogEntry> 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<count!;i++){
// numList2.remove(numList![i]);
// }
// print(numList2);
// await prefs.setStringList("noAddressList", numList2);
// for (int i = 0; i < phoneNum.length; i++) {
// phoneNum2.add(PhoneNumModel(
// num: phoneNum[i].num,
// time: phoneNum[i].time,
// name: phoneNum[i].name,
// state: phoneNum[i].state,
// ));
// }
setState(() {});
}
_getListBox(List item, int index) { _getListBox(List item, int index) {
final service = FlutterBackgroundService();
return GestureDetector( return GestureDetector(
onTap: () { onTap: () async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
select = index; select = index;
await prefs.setInt("numIndex", index);
if(await service.isRunning()){
service.invoke("stopService");
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
}else{
service.startService();
Future.delayed(const Duration(seconds: 1), () async {
service.invoke("stopService");
});
}
// print(_selectIndex); // print(_selectIndex);
setState(() {}); setState(() {});
}, },

Loading…
Cancel
Save