|
|
|
import 'package:bot_toast/bot_toast.dart';
|
|
|
|
import 'package:common_utils/common_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_background_service/flutter_background_service.dart';
|
|
|
|
import 'package:flutter_contacts/flutter_contacts.dart';
|
|
|
|
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
|
|
|
import 'package:project_telephony/utils/headers.dart';
|
|
|
|
import 'package:project_telephony/utils/user_tool.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import '../../../base/base_style.dart';
|
|
|
|
import '../../widget/plone_back_button.dart';
|
|
|
|
import '../call.dart';
|
|
|
|
import '../home_page.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class PhoneSetPage extends StatefulWidget {
|
|
|
|
const PhoneSetPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PhoneSetPageState createState() => _PhoneSetPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PhoneSetPageState extends State<PhoneSetPage> {
|
|
|
|
int select = 0;
|
|
|
|
List<Contact>? contact;
|
|
|
|
List<String> numbers = [];
|
|
|
|
List<String>? numList = [];
|
|
|
|
bool vle=false;
|
|
|
|
bool isVip=false;
|
|
|
|
String? endDate;
|
|
|
|
final EasyRefreshController _refreshController = EasyRefreshController();
|
|
|
|
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
final EasyRefreshController _easyRefreshController=EasyRefreshController();
|
|
|
|
List setList = [
|
|
|
|
// {
|
|
|
|
// "icon": Assets.icons.rylyphone.path,
|
|
|
|
// "title": "任意来源号码发送",
|
|
|
|
// "text": "所有的号码来电都会发送",
|
|
|
|
// // "select": true,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "icon": Assets.icons.txlphone.path,
|
|
|
|
// "title": "在通讯录中的号码发送",
|
|
|
|
// "text": "只给在通讯录中的号码来电发送",
|
|
|
|
// // "select": false,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "icon": Assets.icons.notxlphone.path,
|
|
|
|
// "title": "不在通讯录中的号码发送",
|
|
|
|
// "text": "只给不在通讯录中的号码来电发送",
|
|
|
|
// // "select": false,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
{
|
|
|
|
"icon": Assets.icons.switch1.path,
|
|
|
|
"title": "功能开关",
|
|
|
|
"text": "功能开启所有号码都发送",
|
|
|
|
// "select": true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"icon": Assets.icons.rylyphone.path,
|
|
|
|
"title": "任意来源号码发送",
|
|
|
|
"text": "所有的号码来电都会发送",
|
|
|
|
// "select": true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"icon": Assets.icons.txlphone.path,
|
|
|
|
"title": "来电接听/挂断",
|
|
|
|
"text": "只发来电",
|
|
|
|
// "select": false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"icon": Assets.icons.notxlphone.path,
|
|
|
|
"title": "去电接听/挂断",
|
|
|
|
"text": "只发去电",
|
|
|
|
// "select": false,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_easyRefreshController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return 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 {
|
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
print(prefs.getInt("numIndex"));
|
|
|
|
select = (prefs.getInt("numIndex")) ?? 0;
|
|
|
|
_getRequests();
|
|
|
|
// _viewLoading();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
// _getSwitch(),
|
|
|
|
_getList(),
|
|
|
|
// GestureDetector(
|
|
|
|
// onTap: () {
|
|
|
|
// Get.to(() => const SpecifyPhonePage());
|
|
|
|
// },
|
|
|
|
// child: Container(
|
|
|
|
// padding:
|
|
|
|
// EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w),
|
|
|
|
// height: 144.w,
|
|
|
|
// child: ListTile(
|
|
|
|
// leading: SizedBox(
|
|
|
|
// width: 72.w,
|
|
|
|
// height: 72.w,
|
|
|
|
// child: Image.asset(
|
|
|
|
// Assets.icons.zdphone.path,
|
|
|
|
// fit: BoxFit.fill,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// title: Text(
|
|
|
|
// "指定号码不发送",
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: 32.sp, fontWeight: FontWeight.bold),
|
|
|
|
// ),
|
|
|
|
// subtitle: Text(
|
|
|
|
// "通过添加指定号码来设置不发送",
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: 28.sp, color: const Color(0xFF999999)),
|
|
|
|
// ),
|
|
|
|
// trailing: SizedBox(
|
|
|
|
// width: 48.w,
|
|
|
|
// height: 48.w,
|
|
|
|
// child: const Icon(Icons.arrow_forward_ios),
|
|
|
|
// )),
|
|
|
|
// ),
|
|
|
|
// )
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getList() {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.w),
|
|
|
|
height: 640.w,
|
|
|
|
child: ListView.builder(
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return _getListBox(setList, index,index!=0);
|
|
|
|
},
|
|
|
|
itemCount: setList.length,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
//内容
|
|
|
|
// _getSwitch() {
|
|
|
|
// return Container(
|
|
|
|
// padding: EdgeInsets.symmetric(horizontal: 32.w),
|
|
|
|
// child: ListTile(
|
|
|
|
// // onTap: (() {}),
|
|
|
|
// leading: Image.asset(
|
|
|
|
// Assets.icons.switch1.path,
|
|
|
|
// height: 54.w,
|
|
|
|
// width: 56.w,
|
|
|
|
// fit: BoxFit.fill,
|
|
|
|
// ),
|
|
|
|
// title: Text(
|
|
|
|
// "功能开关",
|
|
|
|
// style: TextStyle(
|
|
|
|
// color: BaseStyle.color333333,
|
|
|
|
// fontSize: BaseStyle.fontSize34,
|
|
|
|
// fontWeight: FontWeight.bold),
|
|
|
|
// ),
|
|
|
|
// trailing: Checkbox(
|
|
|
|
// value: vle,
|
|
|
|
// // 改变后的事件
|
|
|
|
// onChanged: (value) {
|
|
|
|
// setState(() {
|
|
|
|
// vle=value!;
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// // 选中后的颜色
|
|
|
|
// activeColor: Colors.blue,
|
|
|
|
// // 选中后对号的颜色
|
|
|
|
// checkColor: Colors.white,
|
|
|
|
// ),
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// // Switch(
|
|
|
|
// // value: vle,
|
|
|
|
// // onChanged: (value) async {
|
|
|
|
// // final SharedPreferences prefs = await _prefs;
|
|
|
|
// // setState(() {
|
|
|
|
// // if (isVip) {
|
|
|
|
// // vle = value;
|
|
|
|
// // if (vle) {
|
|
|
|
// // print("true");
|
|
|
|
// // prefs.remove("kg");
|
|
|
|
// // prefs.setBool("kg", vle);
|
|
|
|
// // service.startService();
|
|
|
|
// // initializeService();
|
|
|
|
// // BotToast.showText(text: " 你开启了该功能");
|
|
|
|
// // } else {
|
|
|
|
// // prefs.remove("kg");
|
|
|
|
// // prefs.setBool("kg", vle);
|
|
|
|
// // service.invoke("stopService");
|
|
|
|
// // BotToast.showText(text: "你已经关闭该功能");
|
|
|
|
// // }
|
|
|
|
// // } else {
|
|
|
|
// // BotToast.showText(text: "还没有开通会员,不可使用该功能");
|
|
|
|
// // }
|
|
|
|
// // });
|
|
|
|
// // }),
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
// var numberList = await ExcludeFunc.getContacts();
|
|
|
|
// for (int i = 0; i < numberList.length; i++) {
|
|
|
|
// numList?.add(numberList[i].phone);
|
|
|
|
// }
|
|
|
|
// await prefs.setStringList("specified", numList!);
|
|
|
|
// 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(() {});
|
|
|
|
// }
|
|
|
|
_getRequests() async {
|
|
|
|
UserTool.userProvider.updateUserInfo();
|
|
|
|
if (UserTool.userProvider.isLogin) {
|
|
|
|
// print(UserTool.userProvider.userInfo.end * 1000);
|
|
|
|
// print(DateTime.now().millisecondsSinceEpoch);
|
|
|
|
if (UserTool.userProvider.userInfo.isVip != 1) {
|
|
|
|
isVip = false;
|
|
|
|
vle = false;
|
|
|
|
// UserTool.userProvider.updateUserInfo();
|
|
|
|
_easyRefreshController.callRefresh();
|
|
|
|
} else {
|
|
|
|
isVip = true;
|
|
|
|
vle = await service.isRunning();
|
|
|
|
// print(vle);
|
|
|
|
// _easyRefreshController.callRefresh();
|
|
|
|
}
|
|
|
|
//service.isRunning() as bool;
|
|
|
|
// endDate = DateUtil.formatDateMs(
|
|
|
|
// UserTool.userProvider.userInfo.end * 1000,
|
|
|
|
// format: DateFormats.y_mo_d);
|
|
|
|
} else {
|
|
|
|
vle = false;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
_getListBox(List item, int index,bool kg) {
|
|
|
|
final service = FlutterBackgroundService();
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () async {
|
|
|
|
if(kg){
|
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
select = index;
|
|
|
|
await prefs.setInt("numIndex", index);
|
|
|
|
service.invoke("stopService");
|
|
|
|
if (prefs.getBool('kg') ?? false) {
|
|
|
|
|
|
|
|
Future.delayed(const Duration(seconds: 1), () async {
|
|
|
|
vle=true;
|
|
|
|
service.startService();
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
UserTool.userProvider.viewLoading();
|
|
|
|
_refreshController.callRefresh();
|
|
|
|
// print(_selectIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: ListTile(
|
|
|
|
leading: SizedBox(
|
|
|
|
width: 72.w,
|
|
|
|
height: 72.w,
|
|
|
|
child: Image.asset(
|
|
|
|
item[index]["icon"],
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
)),
|
|
|
|
title: Text(
|
|
|
|
item[index]["title"],
|
|
|
|
style: TextStyle(fontSize: 32.sp, fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
item[index]["text"],
|
|
|
|
style: TextStyle(fontSize: 28.sp, color: const Color(0xFF999999)),
|
|
|
|
),
|
|
|
|
trailing: SizedBox(
|
|
|
|
width: 40.w,
|
|
|
|
height: 40.w,
|
|
|
|
child: kg?
|
|
|
|
Radio(
|
|
|
|
onChanged: (int? value) async{
|
|
|
|
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
// select = index;
|
|
|
|
// await prefs.setInt("numIndex", index);
|
|
|
|
// service.invoke("stopService");
|
|
|
|
// if (prefs.getBool('kg')!) {
|
|
|
|
// Future.delayed(const Duration(seconds: 1), () async {
|
|
|
|
// service.startService();
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// UserTool.userProvider.viewLoading();
|
|
|
|
// _refreshController.callRefresh();
|
|
|
|
// select = index;
|
|
|
|
// print(_selectIndex);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
groupValue: select,
|
|
|
|
value: index,
|
|
|
|
):Checkbox(
|
|
|
|
value: vle,
|
|
|
|
// 改变后的事件
|
|
|
|
onChanged: (value) async{
|
|
|
|
final SharedPreferences prefs = await _prefs;
|
|
|
|
// if(!value){
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// await prefs.setBool("kg", value);
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
setState(() {
|
|
|
|
if (isVip) {
|
|
|
|
vle = value!;
|
|
|
|
// prefs.setBool("kg", vle);
|
|
|
|
// initializeService();
|
|
|
|
// print(vle);
|
|
|
|
if (vle) {
|
|
|
|
// print("true");
|
|
|
|
// prefs.remove("kg");
|
|
|
|
prefs.setBool("kg", vle);
|
|
|
|
service.startService();
|
|
|
|
initializeService();
|
|
|
|
BotToast.showText(text: " 你开启了该功能");
|
|
|
|
} else {
|
|
|
|
// print("false");
|
|
|
|
// prefs.remove("kg");
|
|
|
|
prefs.setBool("kg", vle);
|
|
|
|
service.invoke("stopService");
|
|
|
|
BotToast.showText(text: "你已经关闭该功能");
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BotToast.showText(text: "还没有开通会员,不可使用该功能");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 选中后的颜色
|
|
|
|
activeColor: Colors.blue,
|
|
|
|
// 选中后对号的颜色
|
|
|
|
checkColor: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
// BeeCheckRadio(
|
|
|
|
// value: index,
|
|
|
|
// groupValue: [select],
|
|
|
|
// ),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|