import 'package:call_log/call_log.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_sms/flutter_sms.dart'; import 'package:get_phone_number/get_phone_number.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:project_telephony/base/base_style.dart'; import 'package:project_telephony/ui/home/content_details_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:telephony/telephony.dart'; import '../user/privacy_rights_page.dart'; class ContentPage extends StatefulWidget { final bool? isAnswer; //true接听false未接听 const ContentPage({Key? key, required this.isAnswer}) : super(key: key); @override _ContentPageState createState() => _ContentPageState(); } class _ContentPageState extends State { int _select = 0; List textList = ['欢迎你的来电', '祝您生活愉快', '感谢您的来电我们会尽快处理的', '自定义短信内容']; List textList1 = ['自定义短信内容']; late String phoneNum; late String callState; @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 ListView.builder( itemBuilder: (context, index) { return _getBox(textList[index], index == _select, index); }, itemCount: textList.length, ); } _getBox(String content, bool pd, int index) { return GestureDetector( onTap: () async { _select = index; if (index == textList.length - 1) { await Get.to(() => ContentDetailsPage( content: "", ploneBack: (String textContent) { // print("这是数据" + textContent); textList.setAll(index, {textContent}); }, )); } else { bool? permissionsGranted = await telephony.requestPhonePermissions; final Iterable result = await CallLog.query(); phoneNum = result.first.number!; print(phoneNum); // print(permissionsGranted); // if(permissionsGranted!){ // print(content); // // sendSms(content); // telephony.sendSms( // to: "13395740386", // message: content, // ); // }else{ // print(content); // } // print(content); // // sendSms(content); // telephony.sendSms( // to: "13395740386", // message: content, // isMultipart: true // ); List recipents=[ phoneNum ]; _sendSMS(content,recipents); // String phoneNumber = await GetPhoneNumber().get(); // print('getPhoneNumber result: $phoneNumber'); } setState(() {}); // print("这是数据" + textList[_s lect]); // print(index); }, onLongPress: () { if (index != textList.length - 1) { showDialog( context: context, builder: (context) { return const Centertipsalterwidget( desText: '你确定要删除这个短信模版吗,删除之后无法还原。', title: '删除短信模板', ); }); } setState(() {}); }, child: Container( // width: 686.w, height: 135.w, margin: EdgeInsets.only(top: 32.w, left: 64.w, right: 64.w), padding: EdgeInsets.only(left: 40.w, top: 50.w), decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: pd ? widget.isAnswer! ? Colors.blue : const Color(0xFF72E4C8) : const Color(0xFFF9F9F9), ), child: Text( content, style: TextStyle( fontSize: BaseStyle.fontSize28, color: pd ? const Color(0xFFF9F9F9) : BaseStyle.color333333, fontWeight: FontWeight.bold), ), ), ); } void _sendSMS(String message, List recipients) async { String _result = await sendSMS( message: message, recipients: recipients, sendDirect: true) .catchError((onError) { print(onError); }); print(_result); } }