# Conflicts:
#	lib/ui/home/call.dart
#	lib/ui/user/user_page.dart
master
王亚玲 2 years ago
commit aba376110d

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'dart:ui'; import 'dart:ui';
@ -17,30 +16,28 @@ import 'package:telephony/telephony.dart';
import '../../providers/user_provider.dart'; import '../../providers/user_provider.dart';
import '../../utils/user_tool.dart'; import '../../utils/user_tool.dart';
Future<void> initializeService() async { Future<void> initializeService() async {
// SharedPreferences preferences = await SharedPreferences.getInstance(); // SharedPreferences preferences = await SharedPreferences.getInstance();
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
await service.configure( await service.configure(
androidConfiguration: AndroidConfiguration( androidConfiguration: AndroidConfiguration(
// this will be executed when app is in foreground or background in separated isolate // this will be executed when app is in foreground or background in separated isolate
onStart: onStart, onStart: onStart,
// auto start service // auto start service
autoStart: true, autoStart: true,
isForegroundMode: true, isForegroundMode: true,
), ),
iosConfiguration: IosConfiguration( iosConfiguration: IosConfiguration(
// auto start service // auto start service
autoStart: true, autoStart: true,
// this will be executed when app is in foreground in separated isolate // this will be executed when app is in foreground in separated isolate
onForeground: onStart, onForeground: onStart,
// you have to enable background fetch capability on xcode project // you have to enable background fetch capability on xcode project
onBackground: onIosBackground, onBackground: onIosBackground,
), ),
); );
service.startService(); service.startService();
} }
// } // }
bool onIosBackground(ServiceInstance service) { bool onIosBackground(ServiceInstance service) {
@ -49,36 +46,25 @@ bool onIosBackground(ServiceInstance service) {
return true; return true;
} }
void onStart(ServiceInstance service) async { void onStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized(); DartPluginRegistrant.ensureInitialized();
int flag = 0; int flag = 0;
String? phoneNum=""; String? phoneNum = "";
int? callRecords=0; int? callRecords = 0;
String callState; String callState;
service.on('stopService').listen((event) { service.on('stopService').listen((event) {
service.stopSelf(); service.stopSelf();
}); });
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;
String? ref=prefs.getString('refSms'); print(callState+"$flag");
String? con=prefs.getString('conSms'); String? ref = prefs.getString('refSms');
print("这是数据$ref"); String? con = prefs.getString('conSms');
// 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;
// print("object"); // print("object");
final Iterable<CallLogEntry> entry = await CallLog.query(); final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number; phoneNum = entry.first.number;
@ -88,35 +74,39 @@ void onStart(ServiceInstance service) async {
// print('DURATION : ${entry.first.duration}');/// // print('DURATION : ${entry.first.duration}');///
// if(callRecords!=0){ // if(callRecords!=0){
// // if(kg!){ // // if(kg!){
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!); if (flag > 0) {
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
} else {
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
}
// // } // // }
// }else{ // }else{
// print("没接通"); // print("没接通");
if (callRecords != 0) { // if (callRecords != 0) {
print("接通了"); // print("接通了");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了"); // Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
} else { // } else {
print("没接通"); // print("没接通");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了"); // Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
// if(kg!) { // if(kg!) {
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通"); // Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
// } // }
// print('DATE : ${DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!)}');// // print('DATE : ${DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!)}');//
// print("你好$phoneNum"); // print("你好$phoneNum");
// // final inbox = telephony.getInboxSms(); // // final inbox = telephony.getInboxSms();
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "啦啦啦啦啦"); // Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "啦啦啦啦啦");
// telephony.sendSms(to: phoneNum, message: "感谢来电"); // telephony.sendSms(to: phoneNum, message: "感谢来电");
// _sendSMS('',[phoneNum]); // _sendSMS('',[phoneNum]);
// print("你好123123$phoneNum"); // print("你好123123$phoneNum");
// } // }
} flag = 0;
} else if (callState == "RINGING") {
flag++;
// print('flag $flag');
} else if (callState == "OFFHOOK") {
flag++;
// print('flag $flag');
} }
} else if (callState == "RINGING") {
flag++;
// print('flag $flag');
} else if (callState == "OFFHOOK") {
if (flag > 0) flag *= -1;
// print('flag $flag');
} }
}); });
} }

@ -1,5 +1,3 @@
import 'dart:async';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flustars/flustars.dart'; import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -51,15 +49,15 @@ class _UserPageState extends State<UserPage> {
void initState() { void initState() {
super.initState(); super.initState();
if ( UserTool.userProvider.isLogin) { if ( UserTool.userProvider.isLogin) {
Timer.periodic(Duration(seconds: 1), (timer) { print(UserTool.userProvider.userInfo.end*1000);
if (UserTool.userProvider.userInfo.isVip==1 && UserTool.userProvider.userInfo.end>=DateTime.now().millisecondsSinceEpoch ) { print(DateTime.now().millisecondsSinceEpoch);
isVip = false; if (UserTool.userProvider.userInfo.end*1000<=DateTime.now().millisecondsSinceEpoch ) {
vle =false; isVip = false;
} else { vle =false;
vle =true; } else {
isVip = true; vle =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{ }else{
vle = false; vle = false;
@ -291,7 +289,6 @@ class _UserPageState extends State<UserPage> {
value: vle, value: vle,
onChanged: (value) async { onChanged: (value) async {
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
var isRunning = await service.isRunning();
final SharedPreferences prefs = await _prefs; final SharedPreferences prefs = await _prefs;
// if(!value){ // if(!value){
// //
@ -299,7 +296,7 @@ class _UserPageState extends State<UserPage> {
// await prefs.setBool("kg", value); // await prefs.setBool("kg", value);
// print("这是数据${prefs.getBool("kg")}"); // print("这是数据${prefs.getBool("kg")}");
setState(() { setState(() {
if(!isVip){ if(isVip){
vle=value; vle=value;
// prefs.setBool("kg", vle); // prefs.setBool("kg", vle);
@ -313,7 +310,7 @@ class _UserPageState extends State<UserPage> {
// initializeService(); // initializeService();
// UserTool.userProvider.setKg(vle) // UserTool.userProvider.setKg(vle)
// initializeService(); // initializeService();
// initializeService(); initializeService();
BotToast.showText(text: " 你开启了该功能"); BotToast.showText(text: " 你开启了该功能");
// initializeService(); // initializeService();
// print("这是数据${prefs.getBool("kg")}"); // print("这是数据${prefs.getBool("kg")}");

Loading…
Cancel
Save