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.

195 lines
6.2 KiB

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:project_telephony/utils/user_tool.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../base/base_style.dart';
import '../home/add_sms_page.dart';
import '../widget/plone_back_button.dart';
typedef TextCallback = Function(String content);
class TextTemplate extends StatefulWidget {
final TextCallback callback;
const TextTemplate({Key? key,required this.callback}) : super(key: key);
@override
_TextTemplateState createState() => _TextTemplateState();
}
class _TextTemplateState extends State<TextTemplate> {
EasyRefreshController refreshController = EasyRefreshController();
List<String> textList = [];
@override
void initState() {
addText();
super.initState();
}
addText() async {
final prefs = await SharedPreferences.getInstance();
if (textList.length == 1) {
prefs.setStringList("dxText", [
"祝你万事顺心",
"欢迎你的来电,祝你生活愉快",
"感谢您的来电,我们会尽快处理",
]);
}
}
@override
void dispose() {
// TODO: implement dispose
refreshController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
elevation: 0,
title: Text(
'短信模版',
style: TextStyle(
fontSize: BaseStyle.fontSize34,
color: BaseStyle.color333333,
fontWeight: FontWeight.bold),
),
titleSpacing: 162.w,
leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor),
backgroundColor: Colors.white,
body: EasyRefresh(
firstRefresh: true,
controller: refreshController,
header: MaterialHeader(),
footer: MaterialFooter(),
onRefresh: () async {
final prefs = await SharedPreferences.getInstance();
textList = prefs.getStringList("dxText") ?? [];
textList.add("自定义短信模版");
setState(() {});
},
child: ListView(
children: [
SizedBox(
height: 1000.w,
child: ListView.builder(
itemBuilder: (context, index) {
return _getListContent(textList[index], index);
},
itemCount: textList.length,
))
],
),
),
);
}
_getListContent(String item, int index) {
return GestureDetector(
onTap: () async {
final prefs = await SharedPreferences.getInstance();
if (item != "自定义短信模版") {
// BotToast.showText(text: item);
widget.callback(item);
Get.back();
} else {
if (UserTool.userProvider.userInfo.isVip == 1) {
if (textList.length > 5) {
BotToast.showText(text: '自定义数量已达上限,请先删除不需要的短信');
} else {
Navigator.of(context)
.push(
MaterialPageRoute(
builder: (_) => AddSmsPage(status: 0, ploneBack: (String textContent) { },qfBool: true,)),
)
.then((val) =>refreshController.callRefresh());
// textList.add("value");
// await prefs.setStringList("dxTExt", textList);
}
} else {
BotToast.showText(text: '请先开通会员');
}
}
setState(() {});
},
onLongPress: () {
if (item != "自定义短信模版") {
if (textList.length == 3) {
BotToast.showText(text: '内容不可删除');
} else {
showDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: const Text("删除短信模板"),
content: Column(
children: [
SizedBox(
height: 10.w,
),
const Align(
child: Text("你确定要删除这个短信模版吗,删除之后无法还原。"),
)
],
),
actions: [
CupertinoDialogAction(
textStyle: const TextStyle(color: Color(0xFF999999)),
onPressed: () {
Navigator.pop(context);
},
child: const Text("取消"),
),
CupertinoDialogAction(
child: const Text("确定"),
onPressed: () async {
final prefs = await SharedPreferences.getInstance();
textList.remove(item[index]);
await prefs.setStringList("dxIndex", textList);
refreshController.callRefresh();
},
),
],
);
});
}
}
setState(() {});
},
child: Container(
// width: 686.w,
height: 128.w,
margin: EdgeInsets.only(top: 32.w, left: 64.w, right: 64.w),
padding: EdgeInsets.only(left: 40.w, top: 45.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.w),
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xFFF9F9F9),
Color(0xFFF9F9F9),
]),
),
child: Text(
item,
style: TextStyle(
fontSize: BaseStyle.fontSize28,
color: BaseStyle.color333333,
fontWeight: FontWeight.bold),
),
),
);
}
}