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

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

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

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

Loading…
Cancel
Save