王亚玲 2 years ago
parent aba376110d
commit bfeb1c4b43

@ -46,6 +46,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// await initializeService(); // await initializeService();
// Workmanager().initialize( // Workmanager().initialize(
// callbackDispatcher, // The top level function, aka callbackDispatcher // callbackDispatcher, // The top level function, aka callbackDispatcher
// isInDebugMode: true // If enabled it will post a notification whenever the task is running. Handy for debugging tasks // isInDebugMode: true // If enabled it will post a notification whenever the task is running. Handy for debugging tasks

@ -94,9 +94,9 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 2}); var base = await apiClient.request(API.app.find, data: {'status': 2});
if (base.code == 0) { if (base.code == 0) {
// await prefs.remove('refSms'); // await prefs.remove('refSms');
print(base.data['content']); // print(base.data['content']);
await prefs.setString('refSms', base.data['content']); await prefs.setString('refSms', base.data['content']);
print(prefs.getString('refSms')); // print(prefs.getString('refSms'));
service.startService(); service.startService();
// _contentRef = base.data['content']; // _contentRef = base.data['content'];
} else { } else {

@ -60,9 +60,10 @@ void onStart(ServiceInstance service) 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;
print(callState+"$flag"); // print(callState+"$flag");
String? ref = prefs.getString('refSms'); String? ref = prefs.getString('refSms');
String? con = prefs.getString('conSms'); String? con = prefs.getString('conSms');
print("没接通$ref,接通$con");
if (callState == "IDLE") { if (callState == "IDLE") {
if (flag != 0) { if (flag != 0) {
// print("object"); // print("object");
@ -75,9 +76,9 @@ void onStart(ServiceInstance service) async {
// if(callRecords!=0){ // if(callRecords!=0){
// // if(kg!){ // // if(kg!){
if (flag > 0) { if (flag > 0) {
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);//
} else { } else {
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);//
} }
// // } // // }
// }else{ // }else{

@ -44,18 +44,18 @@ 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;
late bool vle; late bool vle=false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if ( UserTool.userProvider.isLogin) { if ( UserTool.userProvider.isLogin) {
print(UserTool.userProvider.userInfo.end*1000); print(UserTool.userProvider.userInfo.end*1000);
print(DateTime.now().millisecondsSinceEpoch); print(DateTime.now().millisecondsSinceEpoch);
if (UserTool.userProvider.userInfo.end*1000<=DateTime.now().millisecondsSinceEpoch ) { if (UserTool.userProvider.userInfo.end*1000<=DateTime.now().millisecondsSinceEpoch ) {
isVip = false; isVip = false;
vle =false; vle =false;
} else { } else {
vle =true;
isVip = 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);
@ -290,6 +290,10 @@ class _UserPageState extends State<UserPage> {
onChanged: (value) async { onChanged: (value) async {
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
final SharedPreferences prefs = await _prefs; final SharedPreferences prefs = await _prefs;
// if(value){
// WidgetsFlutterBinding.ensureInitialized();
// await initializeService();
// }
// if(!value){ // if(!value){
// //
// } // }
@ -305,12 +309,13 @@ class _UserPageState extends State<UserPage> {
print("true"); print("true");
prefs.remove("kg"); prefs.remove("kg");
prefs.setBool("kg", vle); prefs.setBool("kg", vle);
service.startService();
// service.startService();
// WidgetsFlutterBinding.ensureInitialized(); // WidgetsFlutterBinding.ensureInitialized();
// 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