import 'dart:async'; 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/widget/centertipsalterwidget.dart'; import 'package:project_telephony/ui/widget/plone_back_button.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:provider/provider.dart'; import '../../providers/user_provider.dart'; import 'add_sms_page.dart'; class ContentRefusePage extends StatefulWidget { const ContentRefusePage({Key? key}) : super(key: key); @override _ContentRefusePageState createState() => _ContentRefusePageState(); } class _ContentRefusePageState extends State { int _select = 0; List textList = ['现在无法接听。有什么事吗?', '我马上会打给你。', '我稍后会打给你。', "自定义短信内容"]; List textListSMS = []; List smsIdList =[]; final userProvider = Provider.of(Get.context!, listen: false); final EasyRefreshController _easyRefreshController = EasyRefreshController(); @override void initState() { super.initState(); updateList(); } @override void dispose() { _easyRefreshController.dispose(); super.dispose(); } Future updateList() async{ if (userProvider.isLogin) { textListSMS.clear(); userProvider.userInfo.contentRef?.forEach((model) { textListSMS.add(model.content); smsIdList.add(model.id); }); 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: Column(children: [ Expanded( child: _getList(), ), ]), ); } _getList() { return EasyRefresh( firstRefresh: true, header: MaterialHeader(), footer: MaterialFooter(), controller: _easyRefreshController, onRefresh: () async { await updateList(); }, child:ListView.builder( itemBuilder: (context, index) { return _getBox(textListSMS[index], index == _select, index); }, itemCount: textListSMS.length, ), ); } _getBox(String content, bool pd, int index) { return GestureDetector( onTap: () async { if (content != "自定义短信内容") { _select = index; } else { if(userProvider.isLogin){ if(textListSMS.length>5){ BotToast.showText(text: '自定义数量已达上限,请先删除不需要的短信'); }else{ Get.to(AddSmsPage( status: 2, ploneBack: (String textContent) { }, )); } }else{ BotToast.showText(text: '请先登录'); } } setState(() {}); }, onLongPress: () { if(content != "自定义短信内容"){ if (textListSMS.length<2 ) { BotToast.showText(text: '不能再删了'); }else{ showDialog( context: context, builder: (context) { return Centertipsalterwidget( desText: '你确定要删除这个短信模版吗,删除之后无法还原。', title: '删除短信模板', id: smsIdList[index], ); }); } } setState(() { _easyRefreshController.callRefresh(); }); }, 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), color: pd ? const Color(0xFF72E4C8) : const Color(0xFFF9F9F9), ), child: Text( content, style: TextStyle( fontSize: BaseStyle.fontSize28, color: pd ? const Color(0xFFF9F9F9) : BaseStyle.color333333, fontWeight: FontWeight.bold), ), ), ); } }