王亚玲 2 years ago
commit 0b7443f0d9

@ -1,5 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../constants/api.dart';
import '../model/login_info_model.dart';
@ -10,16 +12,21 @@ import '../utils/toast/cloud_toast.dart';
class UserProvider extends ChangeNotifier {
bool _isLogin = false;
bool _kg=false;
bool _kg = false;
bool get kg => _kg;
bool get isLogin => _isLogin;
late UserInfoModel _userInfo;
UserInfoModel get userInfo => _userInfo;
late String _contentCon;
String get contentCon=>_contentCon;
String get contentCon => _contentCon;
late String _contentRef;
String get contentRef=>_contentRef;
String get contentRef => _contentRef;
Future<bool> init() async {
if (HiveStore.appBox?.containsKey('token') ?? false) {
@ -34,11 +41,10 @@ class UserProvider extends ChangeNotifier {
}
}
Future setKg(bool lockage) async{
Future setKg(bool lockage) async {
_kg = lockage;
notifyListeners();
}
}
Future setToken(String token, {User? user}) async {
apiClient.setToken(token);
@ -68,9 +74,14 @@ Future setKg(bool lockage) async{
}
Future updateConSms() async {
var base = await apiClient.request(API.app.find,data: {'status': 1});
final prefs = await SharedPreferences.getInstance();
var base = await apiClient.request(API.app.find, data: {'status': 1});
if (base.code == 0) {
_contentCon = base.data['content'];
await prefs.remove('refSms');
await prefs.setString('conSms', base.data['content']);
print(prefs.getString('action'));
// _contentCon = base.data['content'];
} else {
CloudToast.show(base.msg);
}
@ -78,9 +89,16 @@ Future setKg(bool lockage) async{
}
Future updateRefSms() async {
var base = await apiClient.request(API.app.find,data: {'status': 2});
final prefs = await SharedPreferences.getInstance();
final service=FlutterBackgroundService();
var base = await apiClient.request(API.app.find, data: {'status': 2});
if (base.code == 0) {
_contentRef = base.data['content'];
// await prefs.remove('refSms');
print(base.data['content']);
await prefs.setString('refSms', base.data['content']);
print(prefs.getString('refSms'));
service.startService();
// _contentRef = base.data['content'];
} else {
CloudToast.show(base.msg);
}

@ -7,6 +7,7 @@ import 'package:call_log/call_log.dart';
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';
@ -26,7 +27,7 @@ Future<void> initializeService() async {
// this will be executed when app is in foreground or background in separated isolate
onStart: onStart,
// auto start service
autoStart: false,
autoStart: true,
isForegroundMode: true,
),
iosConfiguration: IosConfiguration(
@ -49,7 +50,8 @@ bool onIosBackground(ServiceInstance service) {
}
void onStart(ServiceInstance service ) async {
void onStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized();
int flag = 0;
String? phoneNum="";
@ -64,6 +66,10 @@ void onStart(ServiceInstance service ) 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")}");
@ -72,18 +78,25 @@ void onStart(ServiceInstance service ) async {
// print("这是数据${prefs.getBool("kg")}");
// print(callState!+" $flag");
if (callState == "IDLE") {
if (flag != 0 ) {
if (flag != 0) {
flag = 0;
// print("object");
final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum=entry.first.number;
phoneNum = entry.first.number;
callRecords = entry.first.duration;
// print(prefs.getString('action'));
// DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!)
// print('DURATION : ${entry.first.duration}');///
if(callRecords!=0){
// if(callRecords!=0){
// // if(kg!){
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
// // }
// }else{
// print("没接通");
if (callRecords != 0) {
print("接通了");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
}else{
} else {
print("没接通");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
// if(kg!) {
@ -96,15 +109,15 @@ void onStart(ServiceInstance service ) async {
// telephony.sendSms(to: phoneNum, message: "感谢来电");
// _sendSMS('',[phoneNum]);
// print("你好123123$phoneNum");
}
// }
}
} else if (callState == "RINGING") {
flag++;
// print('flag $flag');
} else if (callState == "OFFHOOK") {
flag++;
// print('flag $flag');
}
}
});
}

@ -1,5 +1,3 @@
import 'dart:io';
import 'package:bot_toast/bot_toast.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
@ -268,9 +266,6 @@ class _UserPageState extends State<UserPage> {
//
_getSwitch2(){
// final service=FlutterBackgroundService();
// ServiceInstance service;
return Container(
padding: EdgeInsets.symmetric(horizontal: 32.w),
child: ListTile(
@ -329,8 +324,7 @@ class _UserPageState extends State<UserPage> {
// initializeService();
BotToast.showText(text: "你已经关闭该功能");
// print("这是数据${UserTool.userProvider.kg}");
// print("这是数据${prefs.getBool("kg")}");
}
}else{
BotToast.showText(text: "还没有开通会员,不可使用改功能");

Loading…
Cancel
Save