You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
7.1 KiB
228 lines
7.1 KiB
import 'package:bot_toast/bot_toast.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
|
import 'package:project_telephony/base/base_style.dart';
|
|
import 'package:project_telephony/ui/home/add_sms_page.dart';
|
|
import 'package:project_telephony/ui/widget/centertipsalterwidget.dart';
|
|
import 'package:project_telephony/ui/widget/plone_back_button.dart';
|
|
import 'package:project_telephony/utils/headers.dart';
|
|
import 'package:project_telephony/utils/user_tool.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../constants/api.dart';
|
|
import '../../model/network/api_client.dart';
|
|
import '../../model/network/base_model.dart';
|
|
import '../../providers/user_provider.dart';
|
|
import '../../utils/toast/cloud_toast.dart';
|
|
|
|
class ContentConnectPage extends StatefulWidget {
|
|
const ContentConnectPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_ContentConnectPageState createState() => _ContentConnectPageState();
|
|
}
|
|
|
|
class _ContentConnectPageState extends State<ContentConnectPage> {
|
|
List<String> textList = ['欢迎您的来电,祝您生活愉快','自定义短信内容'];
|
|
List<int> smsIdList = [];
|
|
List<String> textListSMS = [];
|
|
int isCheck=0;
|
|
|
|
// final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
|
|
final EasyRefreshController _easyRefreshController = EasyRefreshController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
updateList();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_easyRefreshController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
updateList() {
|
|
if (UserTool.userProvider.isLogin) {
|
|
textListSMS.clear();
|
|
smsIdList.clear();
|
|
int i=0;
|
|
UserTool.userProvider.userInfo.contentCon?.forEach((model) {
|
|
textListSMS.add(model.content);
|
|
smsIdList.add(model.id);
|
|
if(model.isChecked==1){
|
|
isCheck=i;
|
|
}
|
|
i++;
|
|
});
|
|
textListSMS.add("自定义短信内容");
|
|
} else {
|
|
textListSMS = textList;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
elevation: 0,
|
|
title: Text(
|
|
'选择短信内容',
|
|
style: Theme.of(context).textTheme.headline6,
|
|
),
|
|
leading: const CloudBackButton(isSpecial: true),
|
|
backgroundColor: kForeGroundColor,
|
|
),
|
|
backgroundColor: Colors.white,
|
|
body: _getList()
|
|
|
|
// Column(children: [
|
|
// // _getEditContent(),
|
|
// Expanded(child: _getList()),
|
|
//
|
|
//
|
|
// ]),
|
|
);
|
|
}
|
|
|
|
_getList() {
|
|
return
|
|
EasyRefresh(
|
|
firstRefresh: true,
|
|
header: MaterialHeader(),
|
|
footer: MaterialFooter(),
|
|
controller: _easyRefreshController,
|
|
onRefresh: () async {
|
|
await UserTool.userProvider.updateUserInfo();
|
|
updateList();
|
|
setState(() {});
|
|
},
|
|
child: ListView.builder(
|
|
shrinkWrap:true,
|
|
itemBuilder: (context, index) {
|
|
return _getBox(textListSMS[index], index);
|
|
},
|
|
itemCount: textListSMS.length,
|
|
),
|
|
);
|
|
}
|
|
|
|
_getBox(String content, int index) {
|
|
return GestureDetector(
|
|
onTap: () async {
|
|
if (content != "自定义短信内容") {
|
|
BaseModel res = await apiClient.request(API.app.checked,
|
|
data: {'id': smsIdList[index], 'status': 1});
|
|
if (res.code == 0) {
|
|
setState(() {});
|
|
UserTool.userProvider.updateUserInfo();
|
|
UserTool.userProvider.updateConSms();
|
|
_easyRefreshController.callRefresh();
|
|
} else {
|
|
CloudToast.show(res.msg);
|
|
}
|
|
} else {
|
|
if (UserTool.userProvider.userInfo.isVip==1) {
|
|
if (textListSMS.length > 5) {
|
|
BotToast.showText(text: '自定义数量已达上限,请先删除不需要的短信');
|
|
} else {
|
|
Get.to(AddSmsPage(
|
|
status: 1,
|
|
ploneBack: (String textContent) {
|
|
_easyRefreshController.callRefresh();
|
|
},
|
|
));
|
|
}
|
|
} else {
|
|
BotToast.showText(text: '请先开通会员');
|
|
}
|
|
}
|
|
setState(() {});
|
|
},
|
|
onLongPress: () {
|
|
if (content != "自定义短信内容") {
|
|
if (textListSMS.length == 2 || isCheck == index) {
|
|
if(textListSMS.length == 2){
|
|
BotToast.showText(text: '最后一条内容不可删除');
|
|
}else if(isCheck == index){
|
|
BotToast.showText(text: '当前为选中内容,不可删除');
|
|
}
|
|
} else {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return Centertipsalterwidget(
|
|
desText: '你确定要删除这个短信模版吗,删除之后无法还原。',
|
|
title: '删除短信模板',
|
|
id: smsIdList[index],
|
|
callback: (bool status) {
|
|
_easyRefreshController.callRefresh();
|
|
},
|
|
);
|
|
});
|
|
}
|
|
}
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
// width: 686.w,
|
|
margin: EdgeInsets.only(top: 32.w, left: 64.w, right: 64.w),
|
|
padding: EdgeInsets.all(40.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(16.w),
|
|
gradient: LinearGradient(
|
|
begin: Alignment.centerLeft,
|
|
end: Alignment.centerRight,
|
|
colors: [
|
|
index==isCheck? const Color(0xFF74BCFF):const Color(0xFFF9F9F9),
|
|
index==isCheck? const Color(0xFF1890FF):const Color(0xFFF9F9F9),
|
|
]),
|
|
),
|
|
child: Text(
|
|
content,
|
|
style: TextStyle(
|
|
fontSize: BaseStyle.fontSize28,
|
|
color: index==isCheck?const Color(0xFFF9F9F9):BaseStyle.color333333,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
// _getEditContent(){
|
|
// return GestureDetector(
|
|
// onTap: (){
|
|
// if (UserTool.userProvider.userInfo.isVip==1) {
|
|
// if (textListSMS.length > 5) {
|
|
// BotToast.showText(text: '自定义数量已达上限,请先删除不需要的短信');
|
|
// } else {
|
|
// Get.to(AddSmsPage(
|
|
// status: 2,
|
|
// ploneBack: (String textContent) {
|
|
// _easyRefreshController.callRefresh();
|
|
// },
|
|
// ));
|
|
// }
|
|
// } else {
|
|
// BotToast.showText(text: '请先开通会员');
|
|
// }
|
|
// }
|
|
// ,child: Container(
|
|
// width: double.infinity,
|
|
// height: 128.w,
|
|
// margin: EdgeInsets.symmetric(horizontal: 64.w),
|
|
// padding: EdgeInsets.only(left: 40.w,top: 45.w),
|
|
// decoration: BoxDecoration(
|
|
// borderRadius: BorderRadius.circular(16),
|
|
// color: const Color(0xFFF9F9F9),
|
|
// ),
|
|
// child: Text(
|
|
// "定义短信内容",
|
|
// style: TextStyle(
|
|
// fontSize: BaseStyle.fontSize28,
|
|
// color: BaseStyle.color333333,
|
|
// fontWeight: FontWeight.bold),
|
|
// ),
|
|
// ),);
|
|
// }
|
|
}
|