更改提交

master
王亚玲 2 years ago
parent 9bfe528181
commit f88b6f28cc

@ -20,6 +20,7 @@ import 'package:project_telephony/ui/loading.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
import 'package:project_telephony/utils/hive_store.dart';
@ -42,8 +43,9 @@ void main() async {
// LoggerData.addData(details);
// FlutterError.presentError(details);
// };
WidgetsFlutterBinding.ensureInitialized();
WidgetsFlutterBinding.ensureInitialized();
await initializeService();
// Workmanager().initialize(
// 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
@ -64,7 +66,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
final telephony = Telephony.instance;
final prefs = SharedPreferences.getInstance();
Future<void> _Getpermission() async{
await [Permission.sms,Permission.phone,].request();
}

@ -1,14 +0,0 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import '../model/hive/ContentHive.dart';
class ContentListModel extends ChangeNotifier{
late Box _regionBox;
final List<ContentHive> _regions=[];
List<ContentHive> get regions=>_regions;
Future init() async{}
// _regionBox = await Hive.openBox("ContentListBox");
// var
}

@ -1,7 +0,0 @@
// import 'package:flutter/material.dart';
//
// class PhoneProvider extends ChangeNotifier{
// bool sms=false;
// bool phone=false;
//
// }

@ -10,7 +10,8 @@ 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;
@ -29,6 +30,10 @@ class UserProvider extends ChangeNotifier {
}
}
Future setKg(bool lockage) async{
_kg = lockage;
notifyListeners();
}
Future setToken(String token, {User? user}) async {
@ -55,4 +60,5 @@ class UserProvider extends ChangeNotifier {
}
notifyListeners();
}
}

@ -3,25 +3,28 @@ import 'dart:async';
import 'dart:ui';
import 'package:call_log/call_log.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
import '../../providers/user_provider.dart';
Future<void> initializeService() async {
// SharedPreferences preferences = await SharedPreferences.getInstance();
final service = FlutterBackgroundService();
await service.configure(
androidConfiguration: AndroidConfiguration(
// 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(
@ -50,25 +53,39 @@ void onStart(ServiceInstance service ) async {
String? phoneNum="";
int? callRecords=0;
String callState;
// bool? kg= false;
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final SharedPreferences prefs = await _prefs;
// bool? kg=prefs.getBool("kg");
// print(kg);
Timer.periodic(const Duration(seconds: 1), (timer) async {
CallState state = await Telephony.instance.callState;
callState = state.name;
// bool? kg=prefs.getBool("kg");
// print("这是数据$kg");
// kg= await HiveStore.appBox!.get("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;
callRecords = entry.first.duration;
// DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!)
// print('DURATION : ${entry.first.duration}');///
if(callRecords!=0){
print("接通了");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
// if(kg!){
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
// }
}else{
print("没接通");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
// if(kg!) {
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
// }
// print('DATE : ${DateTime.fromMillisecondsSinceEpoch(entry.first.timestamp!)}');//
// print("你好$phoneNum");
// // final inbox = telephony.getInboxSms();
@ -82,6 +99,7 @@ void onStart(ServiceInstance service ) async {
flag++;
// print('flag $flag');
} else if (callState == "OFFHOOK") {
flag++;
// print('flag $flag');
}

@ -38,13 +38,14 @@ class _LoadingState extends State<Loading> {
if (!await userProvider.init()) {
await Get.offAll(() => const LoginPage());
} else {
await Get.offAll(() => const TabNavigator());
Navigator.of(context).pushReplacementNamed("/TabNavigator");
// await Get.offAll(() => const TabNavigator());
}
});
Future.delayed(const Duration(seconds: 3),(){
//3
Navigator.of(context).pushReplacementNamed("/TabNavigator");
});
// Future.delayed(const Duration(seconds: 3),(){
// //3
// Navigator.of(context).pushReplacementNamed("/TabNavigator");
// });
}

@ -13,10 +13,12 @@ import 'package:project_telephony/ui/widget/image_scaffold.dart';
import 'package:project_telephony/ui/widget/plone_bottom.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
import '../../constants/api.dart';
import '../../model/network/api_client.dart';
import '../../providers/user_provider.dart';
import '../../utils/hive_store.dart';
import '../../utils/toast/cloud_toast.dart';
import '../../utils/user_tool.dart';
import '../home/call.dart';
@ -36,19 +38,20 @@ final Telephony telephony = Telephony.instance;
class _UserPageState extends State<UserPage> {
// bool vle = PermissionStatus.denied.isGranted;
//bool vle =PermissionStatus.denied.isGranted;
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
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();
if ( UserTool.userProvider.isLogin) {
if (UserTool.userProvider.userInfo.isVip == 1) {
isVip = true;
} else {
if (UserTool.userProvider.userInfo.end<=DateTime.now().millisecondsSinceEpoch ) {
isVip = false;
} else {
isVip = true;
}
endDate=DateUtil.formatDateMs(UserTool.userProvider.userInfo.end * 1000, format: DateFormats.y_mo_d);
}
@ -71,7 +74,7 @@ class _UserPageState extends State<UserPage> {
72.hb,
_getBanner(),
120.hb,
_getSwitch(Assets.icons.switch1.path, "功能开关", true),
_getSwitch2(),
_getSwitch(Assets.icons.privacy.path, "隐私政策", false),
_getSwitch(Assets.icons.permissions.path, "权限说明", false),
_getSwitch(Assets.icons.sms.path, "短信标签", false),
@ -257,8 +260,55 @@ class _UserPageState extends State<UserPage> {
}
//
_getSwitch2(){
return Container(
padding: EdgeInsets.symmetric(horizontal: 32.w),
child: ListTile(
// onTap: (() {}),
leading: Image.asset(
Assets.icons.switch1.path,
height: 54.w,
width: 56.w,
fit: BoxFit.fill,
),
title: Text(
"功能开关",
style: TextStyle(
color: BaseStyle.color333333,
fontSize: BaseStyle.fontSize34,
fontWeight: FontWeight.bold),
),
trailing: Switch(
value: vle,
onChanged: (value) async {
final SharedPreferences prefs = await _prefs;
await prefs.setBool("kg", value);
print("这是数据${prefs.getBool("kg")}");
setState(() {
if(!isVip){
vle=value;
if(vle){
print("true");
UserTool.userProvider.setKg(vle);
// prefs.setBool("kg", vle);
BotToast.showText(text: " 你开启了该功能");
// print("这是数据${prefs.getBool("kg")}");
}else{
print("false");
UserTool.userProvider.setKg(vle);
// prefs.setBool("kg", vle);
BotToast.showText(text: "你已经关闭该功能");
// print("这是数据${prefs.getBool("kg")}");
}
}else{
BotToast.showText(text: "还没有开通会员,不可使用改功能");
}
});
}),
));
}
_getSwitch(String url, String name, bool pd) {
bool vle = true;
return GestureDetector(
onTap: () async {
if (!pd) {
@ -303,30 +353,7 @@ class _UserPageState extends State<UserPage> {
fontSize: BaseStyle.fontSize34,
fontWeight: FontWeight.bold),
),
trailing: pd
? Switch(
value: vle,
onChanged: (value) async {
// vle=value;
// await initializeService();
// await Permission.phone.request();
// List<Permission> permissions = [
// Permission.sms,
// Permission.phone,
// ];
// PermissionHelper.check(permissions, onSuccess: () {
// print('onSuccess');
// }, onFailed: () {
// print('onFailed');
// }, onOpenSetting: () {
// print('onOpenSetting');
// openAppSettings();
// });
setState(() {
vle=value;
});
})
: const Icon(Icons.keyboard_arrow_right)),
trailing:const Icon(Icons.keyboard_arrow_right)),
),
);
}

@ -1,3 +1,4 @@
// import 'package:project_telephony/providers/phone_provider.dart';
import 'package:provider/provider.dart';
import '../providers/user_provider.dart';
import 'headers.dart';
@ -5,4 +6,5 @@ import 'headers.dart';
class UserTool {
static UserProvider userProvider =
Provider.of<UserProvider>(Get.context!, listen: false);
// static PhoneProvider phoneProvider=Provider.of<PhoneProvider>(Get.context!, listen: false);
}

@ -81,7 +81,6 @@ dependencies:
shared_preferences: ^2.0.15
#刷新组件
flutter_easyrefresh: ^2.2.1
# flutter_gen_runner: ^4.3.0,
# # jdk

Loading…
Cancel
Save