master
王亚玲 3 years ago
parent 7034f87a75
commit 46e3b7a6a0

@ -5,17 +5,10 @@ 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:project_telephony/utils/user_tool.dart';
import 'package:project_telephony/utils/hive_store.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
import '../../providers/user_provider.dart';
import '../../utils/user_tool.dart';
Future<void> initializeService() async { Future<void> initializeService() async {
// SharedPreferences preferences = await SharedPreferences.getInstance(); // SharedPreferences preferences = await SharedPreferences.getInstance();
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
@ -66,23 +59,27 @@ void onStart(ServiceInstance service) async {
// print(con); // print(con);
if (callState == "IDLE") { if (callState == "IDLE") {
print(flag);
if (flag != 0) { if (flag != 0) {
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(phoneNum);
if (flag > 0) { if (flag > 0) {
print("2");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
} else { } else {
print("3");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
} }
flag = 0; flag = 0;
} }
} else if (callState == "RINGING") { } else if (callState == "RINGING") {
flag++; flag++;
// print('flag $flag'); print('通话');
} else if (callState == "OFFHOOK") { } else if (callState == "OFFHOOK") {
if (flag > 0) flag *= -1; if (flag > 0) flag *= -1;
// print('flag $flag'); print('不同话');
} }
}); });
} }

@ -1,7 +1,10 @@
import 'dart:ffi';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flustars/flustars.dart'; import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:project_telephony/base/base_style.dart'; import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/user/user_page.dart';
import 'package:project_telephony/ui/widget/check_radio.dart'; import 'package:project_telephony/ui/widget/check_radio.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart'; import 'package:project_telephony/ui/widget/plone_back_button.dart';
@ -48,9 +51,44 @@ List payWay = [
{'payName': '支付宝支付', 'payUrl': Assets.icons.zhifubao.path} {'payName': '支付宝支付', 'payUrl': Assets.icons.zhifubao.path}
]; ];
class _MembersPageState extends State<MembersPage> { class _MembersPageState extends State<MembersPage> {
int nowPrice=1; int nowPrice=1;
// void initState() {
// super.initState();
// //
// WidgetsBinding.instance.addObserver(this);
//
// setState(() {});
// }
// @override
// void dispose(){
// super.dispose();
// //
// WidgetsBinding.instance.removeObserver(this);
// }
// @override
// void didChangeAppLifecycleState(AppLifecycleState state){
// super.didChangeAppLifecycleState(state);
// switch (state){
// //
// // UI
// case AppLifecycleState.inactive:
// print(1);
// // print("应用处于闲置状态,这种状态的应用应该假设他们可能在任何时候暂停 切换到后台会触发======");
// break;
// case AppLifecycleState.resumed:
// print(2);
// // UserTool.userProvider.updateUserInfo();
// break;
// case AppLifecycleState.paused:
// print(3);
// // print("应用处于不可见状态 后台======");
// break;
// case AppLifecycleState.detached:
// // print("当前页面即将退出======");
// break;
// }
// }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -258,6 +296,7 @@ class _MembersPageState extends State<MembersPage> {
}); });
if (base.code == 0) { if (base.code == 0) {
await PayUtil().callAliPay(base.data); await PayUtil().callAliPay(base.data);
Get.offAll(const UserPage());
} else { } else {
CloudToast.show(base.msg); CloudToast.show(base.msg);
} }
@ -265,13 +304,14 @@ class _MembersPageState extends State<MembersPage> {
Future _wxPay() async { Future _wxPay() async {
var base = await apiClient.request(API.pay.wxpay, data: { var base = await apiClient.request(API.pay.wxpay, data: {
// 'amount': nowPrice,// // 'amount': nowPrice,//
'amount': 0.1, 'amount': 0.01,
}); });
if (base.code == 0) { if (base.code == 0) {
var wxPayModel = WxPayModel.fromJson(base.data); var wxPayModel = WxPayModel.fromJson(base.data);
await PayUtil().callWxPay( await PayUtil().callWxPay(
payModel: wxPayModel, payModel: wxPayModel,
); );
Get.offAll(const UserPage());
} else { } else {
CloudToast.show(base.msg); CloudToast.show(base.msg);
} }

@ -58,7 +58,14 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
leading: const CloudBackButton(isSpecial: true), leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor), backgroundColor: kForeGroundColor),
backgroundColor: Colors.white, backgroundColor: Colors.white,
body: _getRights(), body: Column(children: [
_getRights("获取设备来电状态","用于获取来电状态",plone),
_getRights("获取设备短信权限","用于发送短信",sms),
],)
,
bottomNavigationBar: GestureDetector( bottomNavigationBar: GestureDetector(
onTap:()async{ onTap:()async{
await _launchUrl(); await _launchUrl();
@ -96,16 +103,19 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
throw 'Could not launch $_url'; throw 'Could not launch $_url';
} }
} }
_getRights(){ _getRights( String name,String text,bool state){
return ListTile( return ListTile(
onTap: ()async{ onTap: ()async{
if(!(sms && plone)){ if(state){
// print(sms);
// print(plone);
openAppSettings(); openAppSettings();
}else{
// print("123123123123");
} }
// if(!(sms && plone)){
// // print(sms);
// // print(plone);
// openAppSettings();
// }else{
// // print("123123123123");
// }
// await Permission.phone.request(); // await Permission.phone.request();
// await Permission.sms.request(); // await Permission.sms.request();
// Map<Permission, PermissionStatus> statuses = await [ // Map<Permission, PermissionStatus> statuses = await [
@ -118,16 +128,16 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
// print(await Permission.sms.request().isGranted); // print(await Permission.sms.request().isGranted);
}, },
title: Text( title: Text(
'获取设备来电', name,
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
subtitle: const Text( subtitle: Text(
"获取设备", text,
), ),
trailing: Wrap( trailing: Wrap(
children: [ children: [
Text(sms & plone ?"已允许":"未允许", Text(state ?"已允许":"未允许",
style: TextStyle(color: sms & plone ?Colors.green:Colors.red)), style: TextStyle(color: state ?Colors.green:Colors.red)),
const Icon(Icons.arrow_forward_ios), const Icon(Icons.arrow_forward_ios),
], ],
), ),

Loading…
Cancel
Save