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.

144 lines
4.5 KiB

// import 'dart:async';
// import android.app.PendingIntent;
// import android.telephony.SmsManager;
import 'package:flutter/material.dart';
import 'package:flutter/services.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<ContentPage> {
// static const platform=const MethodChannel("sendSms");
// Future<Null> sendSms( String text) async{
// print("sendSMS");
// try{
// final String result=await platform.invokeMethod('send',<String,dynamic> {"phone":"+8613486828191","msg":text});
// print(result);
// } on PlatformException catch(e){
// print(e.toString());
// }
// }
// SmsManager smsManager = SmsManager.getDefault();
int _select = 0;
List<String> textList = ['欢迎你的来电', '祝您生活愉快', '感谢您的来电我们会尽快处理的', '自定义短信内容'];
List<String> textList1 = ['自定义短信内容'];
@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;
// print(permissionsGranted);
// if(permissionsGranted!){
// print(content);
// // sendSms(content);
// telephony.sendSms(
// to: "13395740386",
// message: content,
// );
// }else{
// print(content);
// }
print(content);
// sendSms(content);
telephony.sendSms(
to: "13486828191",
message: content,
);
}
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),
),
),
);
}
}