# Conflicts:
#	lib/ui/home/call.dart
#	lib/ui/user/user_page.dart
master
戴余标 2 years ago
commit 70723dcdb6

@ -8,12 +8,14 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:get/get.dart';
import 'package:project_telephony/utils/user_tool.dart';
import 'package:project_telephony/utils/hive_store.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
import '../../providers/user_provider.dart';
import '../../utils/user_tool.dart';
@ -55,19 +57,25 @@ void onStart(ServiceInstance service) async {
String? phoneNum="";
int? callRecords=0;
String callState;
// bool? kg= false;
service.on('stopService').listen((event) {
service.stopSelf();
});
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final SharedPreferences prefs = await _prefs;
// bool? kg=prefs.getBool("kg");
// print(kg);
Timer.periodic(const Duration(seconds: 1), (timer) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
CallState state = await Telephony.instance.callState;
callState = state.name;
String? ref=prefs.getString('refSms');
String? con=prefs.getString('conSms');
print(ref);
// bool? kg= prefs.getBool("kg");
// // bool? kg= prefs.getBool("kg");
print("这是数据${prefs.getBool("kg")}");
// print("这是数据$kg");
// kg = UserTool.userProvider.kg;
// print("这是数据${prefs.getBool("kg")}");
// print(callState!+" $flag");
if (callState == "IDLE") {
if (flag != 0) {
flag = 0;
@ -84,6 +92,12 @@ void onStart(ServiceInstance service) async {
// // }
// }else{
// print("没接通");
if(callRecords!=0){
print("接通了");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
}else{
print("没接通");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
// if(kg!) {
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
// }

@ -162,6 +162,7 @@ _getBody() {
onTap: () {
print(title);
if (title == "接听后") {
Get.to(() => const ContentConnectPage());
} else {
Get.to(() => const ContentRefusePage());

@ -43,16 +43,21 @@ class _UserPageState extends State<UserPage> {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
bool isVip = false;
String? endDate;
late bool vle;
@override
void initState() {
super.initState();
if ( UserTool.userProvider.isLogin) {
if (UserTool.userProvider.userInfo.end<=DateTime.now().millisecondsSinceEpoch ) {
isVip = false;
vle =false;
} else {
vle =true;
isVip = true;
}
endDate=DateUtil.formatDateMs(UserTool.userProvider.userInfo.end * 1000, format: DateFormats.y_mo_d);
}else{
vle = false;
}
}
@ -278,24 +283,45 @@ class _UserPageState extends State<UserPage> {
fontWeight: FontWeight.bold),
),
trailing: Switch(
value: isVip,
value: vle,
onChanged: (value) async {
final service = FlutterBackgroundService();
var isRunning = await service.isRunning();
final SharedPreferences prefs = await _prefs;
await prefs.setBool("kg", value);
print("这是数据${prefs.getBool("kg")}");
// if(!value){
//
// }
// await prefs.setBool("kg", value);
// print("这是数据${prefs.getBool("kg")}");
setState(() {
if(!isVip){
isVip=value;
if(isVip){
vle=value;
// prefs.setBool("kg", vle);
// initializeService();
if(vle){
print("true");
UserTool.userProvider.setKg(isVip);
// prefs.setBool("kg", vle);
prefs.remove("kg");
prefs.setBool("kg", vle);
service.startService();
// WidgetsFlutterBinding.ensureInitialized();
// initializeService();
// UserTool.userProvider.setKg(vle)
// initializeService();
// initializeService();
BotToast.showText(text: " 你开启了该功能");
// initializeService();
// print("这是数据${prefs.getBool("kg")}");
}else{
print("false");
UserTool.userProvider.setKg(isVip);
// prefs.setBool("kg", vle);
prefs.remove("kg");
prefs.setBool("kg", vle);
service.invoke("stopService");
// exit(0);
// UserTool.userProvider.setKg(vle);
// prefs.setBool("kg", false);
// initializeService();
BotToast.showText(text: "你已经关闭该功能");
// print("这是数据${prefs.getBool("kg")}");
}

Loading…
Cancel
Save