改写user provide

master
戴余标 2 years ago
parent 3b0bdfac3a
commit b6ca37b6a5

@ -5,6 +5,7 @@ import 'package:project_telephony/utils/user_tool.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../constants/api.dart';
import '../model/exclude_phone_model.dart';
import '../model/login_info_model.dart';
import '../model/network/api_client.dart';
import '../model/user_info_model.dart';
@ -54,6 +55,7 @@ class UserProvider extends ChangeNotifier {
await updateUserInfo();
updateConSms();
updateRefSms();
getExclude();
}
Future logout() async {
@ -79,11 +81,13 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 1});
if (base.code == 0) {
await prefs.remove('conSms');
await prefs.setString('conSms', (UserTool.userProvider.userInfo.tag)==""?"${base
.data['content']}":"${UserTool.userProvider.userInfo.tag}${base
.data['content']}");
await prefs.setString(
'conSms',
(UserTool.userProvider.userInfo.tag) == ""
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if(prefs.getBool('kg')!){
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
@ -91,7 +95,6 @@ class UserProvider extends ChangeNotifier {
} else {
CloudToast.show(base.msg);
}
notifyListeners();
}
@ -101,11 +104,32 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 2});
if (base.code == 0) {
await prefs.remove('refSms');
await prefs.setString('refSms', (UserTool.userProvider.userInfo.tag)==""?"${base
.data['content']}":"${UserTool.userProvider.userInfo.tag}${base
.data['content']}" );
await prefs.setString(
'refSms',
(UserTool.userProvider.userInfo.tag) == ""
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
}
} else {
CloudToast.show(base.msg);
}
notifyListeners();
}
Future getExclude() async {
final prefs = await SharedPreferences.getInstance();
final service = FlutterBackgroundService();
var base = await apiClient.request(API.exclude.find);
if (base.code == 0) {
await prefs.remove('exclude');
await prefs.setStringList('exclude', base.data);
service.invoke("stopService");
if(prefs.getBool('kg')!){
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});

@ -1,14 +1,8 @@
import 'dart:async';
import 'dart:ui';
import 'package:call_log/call_log.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
@ -63,32 +57,44 @@ void onStart(ServiceInstance service) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
CallState state = await Telephony.instance.callState;
callState = state.name;
print(callState+"$flag");
print(callState + "$flag");
String? ref = prefs.getString('refSms');
String? con = prefs.getString('conSms');
// print(con);
if (callState == "IDLE") {
//
if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number;
callRecords = entry.first.duration;
print(phoneNum);
if (flag > 0) {
print("2");
print("来电拒接/未接");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
print("发送成功");
} else {
print("3");
} else if(flag==-1){
print("来电接听");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
}else {
print(entry.first.callType);
print(entry.first.duration);
if(entry.first.duration!>0){
print("去电接听");
}else{
print("去电未接");
}
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
print("发送成功");
}
flag = 0;
}
} else if (callState == "RINGING") {
flag++;
//
flag=1;
print('通话');
} else if (callState == "OFFHOOK") {
//
if (flag > 0) flag *= -1;
if(flag==0)flag=-2;
print('不通话');
}
});

Loading…
Cancel
Save