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

@ -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';
@ -11,16 +13,21 @@ import '../utils/toast/cloud_toast.dart';
class UserProvider extends ChangeNotifier {
bool _isLogin = 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;
late String _contentRef;
String get contentRef => _contentRef;
Future<bool> init() async {
if (HiveStore.appBox?.containsKey('token') ?? false) {
final token = HiveStore.appBox?.get('token') as String;
@ -39,7 +46,6 @@ Future setKg(bool lockage) async{
notifyListeners();
}
Future setToken(String token, {User? user}) async {
apiClient.setToken(token);
await HiveStore.appBox!.put('token', token);
@ -68,9 +74,14 @@ Future setKg(bool lockage) async{
}
Future updateConSms() async {
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 {
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:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -47,6 +48,7 @@ bool onIosBackground(ServiceInstance service) {
}
void onStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized();
int flag = 0;
@ -62,11 +64,10 @@ void onStart(ServiceInstance service ) async {
Timer.periodic(const Duration(seconds: 1), (timer) async {
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");
// print("这是数据$kg");
// kg= await HiveStore.appBox!.get("kg");
// print(callState!+" $flag");
if (callState == "IDLE") {
if (flag != 0) {
flag = 0;
@ -74,16 +75,15 @@ void onStart(ServiceInstance service ) async {
final Iterable<CallLogEntry> entry = await CallLog.query();
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){
print("接通了");
// if(kg!){
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
// }
}else{
print("没接通");
// if(callRecords!=0){
// // if(kg!){
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
// // }
// }else{
// print("没接通");
// if(kg!) {
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
// }
@ -94,7 +94,7 @@ void onStart(ServiceInstance service ) async {
// telephony.sendSms(to: phoneNum, message: "感谢来电");
// _sendSMS('',[phoneNum]);
// print("你好123123$phoneNum");
}
// }
}
} else if (callState == "RINGING") {
flag++;

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

Loading…
Cancel
Save