|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:bot_toast/bot_toast.dart';
|
|
|
|
|
import 'package:flustars/flustars.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:flutter_background_service/flutter_background_service.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:project_telephony/base/base_style.dart';
|
|
|
|
|
import 'package:project_telephony/ui/login/login_page.dart';
|
|
|
|
@ -43,17 +46,21 @@ 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;
|
|
|
|
|
late bool vle;
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
if ( UserTool.userProvider.isLogin) {
|
|
|
|
|
if (UserTool.userProvider.userInfo.end<=DateTime.now().millisecondsSinceEpoch ) {
|
|
|
|
|
isVip = false;
|
|
|
|
|
vle =false;
|
|
|
|
|
} else {
|
|
|
|
|
vle =true;
|
|
|
|
|
isVip = true;
|
|
|
|
|
}
|
|
|
|
|
endDate=DateUtil.formatDateMs(UserTool.userProvider.userInfo.end * 1000, format: DateFormats.y_mo_d);
|
|
|
|
|
}else{
|
|
|
|
|
vle = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -261,6 +268,9 @@ class _UserPageState extends State<UserPage> {
|
|
|
|
|
|
|
|
|
|
//内容
|
|
|
|
|
_getSwitch2(){
|
|
|
|
|
// final service=FlutterBackgroundService();
|
|
|
|
|
// ServiceInstance service;
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 32.w),
|
|
|
|
|
child: ListTile(
|
|
|
|
@ -281,24 +291,46 @@ class _UserPageState extends State<UserPage> {
|
|
|
|
|
trailing: Switch(
|
|
|
|
|
value: vle,
|
|
|
|
|
onChanged: (value) async {
|
|
|
|
|
final service = FlutterBackgroundService();
|
|
|
|
|
var isRunning = await service.isRunning();
|
|
|
|
|
final SharedPreferences prefs = await _prefs;
|
|
|
|
|
await prefs.setBool("kg", value);
|
|
|
|
|
print("这是数据${prefs.getBool("kg")}");
|
|
|
|
|
// if(!value){
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// await prefs.setBool("kg", value);
|
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
|
setState(() {
|
|
|
|
|
if(!isVip){
|
|
|
|
|
vle=value;
|
|
|
|
|
|
|
|
|
|
// prefs.setBool("kg", vle);
|
|
|
|
|
// initializeService();
|
|
|
|
|
if(vle){
|
|
|
|
|
print("true");
|
|
|
|
|
UserTool.userProvider.setKg(vle);
|
|
|
|
|
// prefs.setBool("kg", vle);
|
|
|
|
|
prefs.remove("kg");
|
|
|
|
|
prefs.setBool("kg", vle);
|
|
|
|
|
service.startService();
|
|
|
|
|
// WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
// initializeService();
|
|
|
|
|
// UserTool.userProvider.setKg(vle)
|
|
|
|
|
// initializeService();
|
|
|
|
|
// initializeService();
|
|
|
|
|
BotToast.showText(text: " 你开启了该功能");
|
|
|
|
|
// initializeService();
|
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
|
}else{
|
|
|
|
|
print("false");
|
|
|
|
|
UserTool.userProvider.setKg(vle);
|
|
|
|
|
// prefs.setBool("kg", vle);
|
|
|
|
|
prefs.remove("kg");
|
|
|
|
|
prefs.setBool("kg", vle);
|
|
|
|
|
service.invoke("stopService");
|
|
|
|
|
// exit(0);
|
|
|
|
|
// UserTool.userProvider.setKg(vle);
|
|
|
|
|
// prefs.setBool("kg", false);
|
|
|
|
|
// initializeService();
|
|
|
|
|
|
|
|
|
|
BotToast.showText(text: "你已经关闭该功能");
|
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
|
|
|
|
|
|
// print("这是数据${UserTool.userProvider.kg}");
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
BotToast.showText(text: "还没有开通会员,不可使用改功能");
|
|
|
|
|