去电开关

master
戴余标 2 years ago
parent 248abb8dbf
commit 6b13a7430b

@ -27,7 +27,10 @@ class AddSmsPage extends StatefulWidget {
class _AddSmsPageState extends State<AddSmsPage> {
late TextEditingController _controller;
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
String contant="";
@override
void initState() {
super.initState();
@ -99,8 +102,20 @@ class _AddSmsPageState extends State<AddSmsPage> {
if (res.code == 0) {
setState(() {});
widget.ploneBack(_controller.text);
UserTool.userProvider.updateUserInfo();
// userProvider.updateUserInfo();
switch (widget.status) {
case 1:
await userProvider.updateConSms();
break;
case 2:
await userProvider.updateRefSms();
break;
case 3:
await userProvider.updateCallSms();
break;
case 4:
await userProvider.updateIdleSms();
break;
}
} else {
CloudToast.show(res.msg);
}

@ -63,6 +63,8 @@ void onStart(ServiceInstance service) async {
String? con = prefs.getString('conSms');
String? call = prefs.getString('callSms');
String? idle = prefs.getString('idleSms');
bool? callSw = prefs.getBool('callSwitch');
bool? idleSw = prefs.getBool('idleSwitch');
if (callState == "IDLE") {
if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query();
@ -78,13 +80,16 @@ void onStart(ServiceInstance service) async {
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
}else {
if(entry.first.duration!>0){
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: call!);
if(callSw!){
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: call!);
}
print("去电接听");
}else{
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle!);
if(idleSw!){
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle!);
}
print("去电未接");
}
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
print("发送成功");
}
flag = 0;

@ -7,6 +7,7 @@ import 'package:get/get.dart';
import 'package:project_telephony/extensions/num_ext.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../base/base_style.dart';
import '../../constants/api.dart';
@ -17,19 +18,20 @@ import '../../providers/user_provider.dart';
import '../../utils/toast/cloud_toast.dart';
import '../widget/centertipsalterwidget.dart';
import 'add_sms_page.dart';
import 'home_page.dart';
class CallingIdleList extends StatefulWidget {
final EasyRefreshController refreshController;
final String title;
final int status;
final bool? isIdle;
final String? name;
final Color themeColor;
const CallingIdleList({
Key? key,
required this.title,
required this.status,
this.isIdle = false,
this.name = '',
required this.themeColor,
required this.refreshController,
}) : super(key: key);
@ -41,17 +43,24 @@ class CallingIdleList extends StatefulWidget {
class _CallingIdleListState extends State<CallingIdleList>
with AutomaticKeepAliveClientMixin {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
List<String> textList = ['现在无法接听。有什么事吗?', '自定义短信内容'];
List<SmsContentModel> _model = [];
List<String> textListSMS = [];
List<int> smsIdList = [];
int isCheck = 0;
bool val = false;
late bool val = false;
@override
void initState() {
getSwitch();
super.initState();
updateList();
}
Future<void> getSwitch() async {
final SharedPreferences prefs = await _prefs;
val = prefs.getBool(widget.name!)!;
print(val);
}
Future<void> updateList() async {
@ -88,39 +97,15 @@ class _CallingIdleListState extends State<CallingIdleList>
children: [
_getText(),
32.hb,
widget.isIdle!
? val
? Expanded(
child: EasyRefresh.custom(
firstRefresh: true,
controller: widget.refreshController,
header: MaterialHeader(),
// footer: MaterialFooter(),
onRefresh: () async {
await userProvider.updateUserInfo();
await updateList();
setState(() {});
},
slivers: [
SliverList(
delegate:
SliverChildBuilderDelegate((context, index) {
return _getBox(textListSMS[index], index);
}, childCount: textListSMS.length),
),
],
),
)
: _getEmptyList()
: Expanded(
widget.name!.isEmpty || val
? Expanded(
child: EasyRefresh.custom(
firstRefresh: true,
controller: widget.refreshController,
header: MaterialHeader(),
// footer: MaterialFooter(),
onRefresh: () async {
await userProvider.updateUserInfo();
userProvider.updateRefSms();
// await userProvider.updateUserInfo();
await updateList();
setState(() {});
},
@ -132,7 +117,8 @@ class _CallingIdleListState extends State<CallingIdleList>
),
],
),
),
)
: _getEmptyList(),
],
);
}
@ -142,23 +128,35 @@ class _CallingIdleListState extends State<CallingIdleList>
height: 128.w,
padding: EdgeInsets.only(left: 40.w, top: 45.w),
child: ListTile(
title: Text(
"功能讲解",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 36.sp),
),
subtitle: Text(
widget.title,
style: TextStyle(color: const Color(0xFF999999), fontSize: 27.sp),
title: Text(
"功能讲解",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 36.sp),
),
subtitle: Text(
widget.title,
style: TextStyle(color: const Color(0xFF999999), fontSize: 27.sp),
),
trailing: Offstage(
offstage: widget.name!.isEmpty,
child: Switch(
value: val,
onChanged: (value) async {
final SharedPreferences prefs = await _prefs;
setState(() {
val = value;
prefs.remove(widget.name!);
prefs.setBool(widget.name!, val);
});
service.invoke("stopService");
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
}
},
),
trailing: widget.isIdle!
? Switch(
value: val,
onChanged: (value) async {
setState(() {
val = value;
});
})
: const SizedBox()),
),
),
);
}
@ -170,7 +168,7 @@ class _CallingIdleListState extends State<CallingIdleList>
data: {'id': smsIdList[index], 'status': widget.status});
if (res.code == 0) {
setState(() {});
await userProvider.updateUserInfo();
// await userProvider.updateUserInfo();
switch (widget.status) {
case 1:
await userProvider.updateConSms();

@ -5,6 +5,7 @@ import 'package:project_telephony/ui/home/calling_idle_list.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tab_indicator_styler/tab_indicator_styler.dart';
@ -25,12 +26,12 @@ class _ContentConnectPageState extends State<ContentConnectPage>
@override
void initState() {
super.initState();
_tabController = TabController(
length: 2,
initialIndex: 0,
vsync: this,
);
super.initState();
}
@override
@ -109,7 +110,7 @@ class _ContentConnectPageState extends State<ContentConnectPage>
),
CallingIdleList(
refreshController: _answerRefreshController,
isIdle: true,
name: "callSwitch",
title: '您给朋友去电接听后所发送的短信',
status: 3,
themeColor: const Color(0xFF1890FF),

@ -3,6 +3,7 @@ import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tab_indicator_styler/tab_indicator_styler.dart';
import 'calling_idle_list.dart';
@ -21,10 +22,12 @@ class _ContentRefusePageState extends State<ContentRefusePage>
EasyRefreshController();
final EasyRefreshController _wasCalledRefreshController =
EasyRefreshController();
bool? idleSwitch=true;
@override
void initState() {
_tabController = TabController(length: 2, initialIndex: 0, vsync: this);
getSwitch();
super.initState();
}
@ -36,6 +39,11 @@ class _ContentRefusePageState extends State<ContentRefusePage>
super.dispose();
}
Future<void> getSwitch()async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
idleSwitch=prefs.getBool("idleSwitch");
}
@override
Widget build(BuildContext context) {
super.build(context);
@ -97,13 +105,12 @@ class _ContentRefusePageState extends State<ContentRefusePage>
controller: _tabController,
children:[
CallingIdleList(
isIdle: false,
status: 2,
themeColor: const Color(0xFF13CA9D),
title: '朋友给你来电接听后所发送的短信', refreshController: _callingRefreshController,
),
CallingIdleList(
isIdle: true,
name: "idleSwitch",
status: 4,
title: '您给朋友去电拒接/未接后所发送的短信',
themeColor: const Color(0xFF13CA9D), refreshController: _wasCalledRefreshController,

@ -43,12 +43,12 @@ class AppDialog extends Dialog {
_getVip(),
200.hb,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
72.wb,
_getText("接听发送"),
64.wb,
60.wb,
_getText("拒接发送"),
64.wb,
60.wb,
_getText("提升形象"),
],
),

Loading…
Cancel
Save