master
戴余标 2 years ago
parent 991a01c6f8
commit e5815a5a8c

@ -1,5 +1,7 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.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 '../constants/api.dart';
import '../model/login_info_model.dart'; import '../model/login_info_model.dart';
@ -10,16 +12,21 @@ import '../utils/toast/cloud_toast.dart';
class UserProvider extends ChangeNotifier { class UserProvider extends ChangeNotifier {
bool _isLogin = false; bool _isLogin = false;
bool _kg=false; bool _kg = false;
bool get kg => _kg; bool get kg => _kg;
bool get isLogin => _isLogin; bool get isLogin => _isLogin;
late UserInfoModel _userInfo; late UserInfoModel _userInfo;
UserInfoModel get userInfo => _userInfo; UserInfoModel get userInfo => _userInfo;
late String _contentCon; late String _contentCon;
String get contentCon=>_contentCon;
String get contentCon => _contentCon;
late String _contentRef; late String _contentRef;
String get contentRef=>_contentRef;
String get contentRef => _contentRef;
Future<bool> init() async { Future<bool> init() async {
if (HiveStore.appBox?.containsKey('token') ?? false) { 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; _kg = lockage;
notifyListeners(); notifyListeners();
} }
Future setToken(String token, {User? user}) async { Future setToken(String token, {User? user}) async {
apiClient.setToken(token); apiClient.setToken(token);
@ -68,9 +74,14 @@ Future setKg(bool lockage) async{
} }
Future updateConSms() 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) { 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 { } else {
CloudToast.show(base.msg); CloudToast.show(base.msg);
} }
@ -78,9 +89,16 @@ Future setKg(bool lockage) async{
} }
Future updateRefSms() 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) { 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 { } else {
CloudToast.show(base.msg); CloudToast.show(base.msg);
} }

@ -7,6 +7,7 @@ import 'package:call_log/call_log.dart';
import 'package:flutter/cupertino.dart'; 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:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -47,7 +48,8 @@ bool onIosBackground(ServiceInstance service) {
} }
void onStart(ServiceInstance service ) async {
void onStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized(); DartPluginRegistrant.ensureInitialized();
int flag = 0; int flag = 0;
String? phoneNum=""; String? phoneNum="";
@ -62,28 +64,26 @@ void onStart(ServiceInstance service ) async {
Timer.periodic(const Duration(seconds: 1), (timer) async { Timer.periodic(const Duration(seconds: 1), (timer) async {
CallState state = await Telephony.instance.callState; CallState state = await Telephony.instance.callState;
callState = state.name; callState = state.name;
String? ref=prefs.getString('refSms');
String? con=prefs.getString('conSms');
print(ref);
// bool? kg=prefs.getBool("kg");
// print("这是数据$kg");
// kg= await HiveStore.appBox!.get("kg");
// print(callState!+" $flag");
if (callState == "IDLE") { if (callState == "IDLE") {
if (flag != 0 ) { if (flag != 0) {
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;
callRecords = entry.first.duration; callRecords = entry.first.duration;
// print(prefs.getString('action'));
// DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!) // DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!)
// print('DURATION : ${entry.first.duration}');/// // print('DURATION : ${entry.first.duration}');///
if(callRecords!=0){ // if(callRecords!=0){
print("接通了"); // // if(kg!){
// if(kg!){ Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了"); // // }
// } // }else{
}else{ // print("没接通");
print("没接通");
// if(kg!) { // if(kg!) {
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通"); // Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
// } // }
@ -94,7 +94,7 @@ void onStart(ServiceInstance service ) async {
// telephony.sendSms(to: phoneNum, message: "感谢来电"); // telephony.sendSms(to: phoneNum, message: "感谢来电");
// _sendSMS('',[phoneNum]); // _sendSMS('',[phoneNum]);
// print("你好123123$phoneNum"); // print("你好123123$phoneNum");
} // }
} }
} else if (callState == "RINGING") { } else if (callState == "RINGING") {
flag++; flag++;

@ -43,7 +43,6 @@ 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;
bool vle = UserTool.userProvider.userInfo.isVip==1;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -279,23 +278,23 @@ class _UserPageState extends State<UserPage> {
fontWeight: FontWeight.bold), fontWeight: FontWeight.bold),
), ),
trailing: Switch( trailing: Switch(
value: vle, value: isVip,
onChanged: (value) async { onChanged: (value) async {
final SharedPreferences prefs = await _prefs; final SharedPreferences prefs = await _prefs;
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; isVip=value;
if(vle){ if(isVip){
print("true"); print("true");
UserTool.userProvider.setKg(vle); UserTool.userProvider.setKg(isVip);
// prefs.setBool("kg", vle); // prefs.setBool("kg", vle);
BotToast.showText(text: " 你开启了该功能"); BotToast.showText(text: " 你开启了该功能");
// print("这是数据${prefs.getBool("kg")}"); // print("这是数据${prefs.getBool("kg")}");
}else{ }else{
print("false"); print("false");
UserTool.userProvider.setKg(vle); UserTool.userProvider.setKg(isVip);
// prefs.setBool("kg", vle); // prefs.setBool("kg", vle);
BotToast.showText(text: "你已经关闭该功能"); BotToast.showText(text: "你已经关闭该功能");
// print("这是数据${prefs.getBool("kg")}"); // print("这是数据${prefs.getBool("kg")}");

Loading…
Cancel
Save