import 'dart:typed_data'; import 'dart:ui'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:qr_flutter/qr_flutter.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/app_settings/app_colors.dart'; import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; import 'package:star_lock/tools/submitBtn.dart'; typedef AuthInfoCallback = void Function(String? idCard, String? name); class ShowCupertinoAlertView { bool isSystemEmailSelected = true; // 默认选中系统邮件 final GlobalKey _repaintBoundaryKey = GlobalKey(); //微信公众号二维码弹窗 void showQRImageAlert( BuildContext widgetContext, String qrCodeUrl, String qrCodeText) { showCupertinoModalPopup( context: widgetContext, builder: (BuildContext context) { return CupertinoActionSheet( actions: [ Container( color: Colors.white, // 设置底色为白色 child: CupertinoActionSheetAction( child: Container( margin: const EdgeInsets.all(0), child: Column( children: [ SizedBox( height: 60.h, ), if (qrCodeUrl.isNotEmpty) Image.network( qrCodeUrl, width: 400.w, height: 400.w, ) else Container(), SizedBox( height: 20.h, ), Padding( padding: EdgeInsets.only(left: 60.w, right: 60.w), child: Text( '${"开启微信接收报警消息需要先关注".tr}$qrCodeText${"微信公众号,请保存二维码并使用微信扫一扫设置".tr}', style: TextStyle(fontSize: 24.sp, color: Colors.black), )), SizedBox( height: 60.h, ) ], ), ), onPressed: () { Navigator.of(context).pop(); }, ), ), ], ); }, ); } //高级功能弹窗 void advancedFeatureAlert() { showCupertinoDialog( context: Get.context!, builder: (context) { return CupertinoAlertDialog( title: Container( margin: EdgeInsets.only(bottom: 20.h), child: Image.asset( 'images/icon_gift.png', width: 50.w, height: 50.w, ), ), content: Text('该功能是高级功能,请开通后再使用'.tr), actions: [ CupertinoDialogAction( child: Text( '取消'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: Get.back, ), CupertinoDialogAction( child: Text( '去开通'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: () async { Get.toNamed(Routers.advancedFeaturesWebPage, arguments: { 'webBuyType': XSConstantMacro.webBuyTypeVip, }); }, ), ], ); }); } //高级功能顶部提示框 Widget topTipsAdvancedFeatures(String tipsText) { return Container( color: AppColors.vipFeatureBgColor, padding: EdgeInsets.only(left: 20.w), height: 80.h, width: 1.sw, child: Row( children: [ Flexible( child: Text(tipsText, style: TextStyle( color: AppColors.vipFeatureBtnTextColor, fontSize: 22.sp)), ), SizedBox( width: 10.w, ), SizedBox( width: 146.w, height: 46.h, child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: AppColors.vipFeatureBtnBgColor, ), onPressed: () { Get.toNamed(Routers.advancedFeaturesWebPage, arguments: { 'webBuyType': XSConstantMacro.webBuyTypeVip, }); }, child: Text( '去开通'.tr, style: TextStyle(color: Colors.white, fontSize: 22.sp), )), ), SizedBox(width: 2.w) // Expanded( // child: SizedBox( // width: 2.w, // )) ], ), ); } //发送需要实名认证的电子钥匙时身份信息确认框 void realNameIDCardInfoComfirmAlert( {required String getNameStr, required String getIDCardStr, required VoidCallback onConfirm}) { showCupertinoDialog( context: Get.context!, builder: (context) { return CupertinoAlertDialog( title: Text('请确认姓名全名和身份证号码是否正确'.tr), content: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 10.h, ), Column( mainAxisAlignment: MainAxisAlignment.start, children: [ Text( '姓名 ', style: TextStyle(fontSize: 22.sp, color: Colors.black), ), Text( '身份证', style: TextStyle(fontSize: 22.sp, color: Colors.black), ) ], ), SizedBox( width: 10.w, ), Column( mainAxisAlignment: MainAxisAlignment.start, children: [ Text( getNameStr, style: TextStyle(fontSize: 22.sp, color: Colors.black), ), Text( getIDCardStr, style: TextStyle(fontSize: 22.sp, color: Colors.black), ) ], ) ], ), actions: [ CupertinoDialogAction( child: Text( '取消'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: Get.back, ), CupertinoDialogAction( child: Text( '确定'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: () async { // 执行回调函数 onConfirm(); Get.back(); }, ), ], ); }); } //打开实名认证弹出输入身份证信息框 void showOpenAuthWithIDCardInfoAlert(AuthInfoCallback callback) { showCupertinoDialog( context: Get.context!, builder: (BuildContext context) { String idCard = ''; String name = ''; return CupertinoAlertDialog( title: Text('请输入身份证号和真实姓名'.tr), content: Column( children: [ SizedBox( height: 10.h, ), CupertinoTextField( placeholder: '请输入身份证号'.tr, onChanged: (value) { idCard = value; }, ), SizedBox( height: 10.h, ), CupertinoTextField( placeholder: '请输入真实姓名'.tr, onChanged: (value) { name = value; }, ), ], ), actions: [ CupertinoDialogAction( onPressed: Get.back, child: Text( '取消'.tr, style: TextStyle(color: AppColors.mainColor), ), ), CupertinoDialogAction( onPressed: () { // 在这里处理确认按钮的逻辑 if (idCard.isEmpty || name.isEmpty) { EasyLoading.showToast('请输入身份证号和真实姓名'.tr); return; } callback(idCard, name); Get.back(); }, child: Text( '确定'.tr, style: TextStyle(color: AppColors.mainColor), ), ), ], ); }, ); } //是否要远程开锁弹窗 void isToRemoteUnLockAlert({required Function remoteUnlockAction}) { showCupertinoDialog( context: Get.context!, builder: (BuildContext context) { return CupertinoAlertDialog( title: Container(), content: Text('是否要远程开锁'.tr), actions: [ CupertinoDialogAction( onPressed: Get.back, child: Text( '取消'.tr, style: TextStyle(color: AppColors.mainColor), ), ), CupertinoDialogAction( onPressed: () { // 在这里处理确认按钮的逻辑 remoteUnlockAction(); Get.back(); }, child: Text( '远程开锁'.tr, style: TextStyle(color: AppColors.mainColor), ), ), ], ); }, ); } // 购买按钮 void showBuyTipWithContentAlert( {required String titleStr, required Function sureClick}) { showCupertinoDialog( context: Get.context!, builder: (context) { return CupertinoAlertDialog( title: Text(titleStr), actions: [ CupertinoDialogAction( child: Text( '取消'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: Get.back, ), CupertinoDialogAction( child: Text('购买'.tr, style: TextStyle(color: AppColors.mainColor)), onPressed: () { Get.back(); sureClick(); }, ), ], ); }, ); } // 联系管理员购买 void showContactAdministratorBuyAlert() { showCupertinoDialog( context: Get.context!, builder: (context) { return CupertinoAlertDialog( title: Text('实名认证为付费功能,请联系锁的管理员购买后再使用'.tr), actions: [ CupertinoDialogAction( child: Text( '确定'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: Get.back, ), ], ); }, ); } //清空操作记录弹窗 void showClearOperationRecordAlert({required Function clearClick}) { showCupertinoDialog( context: Get.context!, builder: (context) { return CupertinoAlertDialog( title: Text('是否要删除操作记录?'.tr), content: Text('被删除的记录不能恢复'.tr), actions: [ CupertinoDialogAction( child: Text( '取消'.tr, style: TextStyle(color: AppColors.mainColor), ), onPressed: Get.back, ), CupertinoDialogAction( child: Text('删除'.tr, style: TextStyle(color: AppColors.mainColor)), onPressed: () { Get.back(); clearClick(); }, ), ], ); }, ); } //可视门铃二维码弹窗 void showVisualDoorbellCodeAlert( {required BuildContext widgetContext, required String qrCodeUrl, required String qrCodeText}) { showCupertinoModalPopup( context: widgetContext, builder: (BuildContext context) { return CupertinoActionSheet( actions: [ Container( color: Colors.white, // 设置底色为白色 child: CupertinoActionSheetAction( child: Container( margin: const EdgeInsets.all(0), child: Column( children: [ SizedBox( height: 60.h, ), if (qrCodeUrl.isNotEmpty) RepaintBoundary( key: _repaintBoundaryKey, child: SizedBox( width: 200, height: 200, child: QrImageView( data: qrCodeUrl, version: QrVersions.auto, size: 200.0, ), ), ) else Container(), SizedBox( height: 20.h, ), Padding( padding: EdgeInsets.only( left: 60.w, right: 60.w, bottom: 30), child: Text( qrCodeText, style: TextStyle(fontSize: 24.sp, color: Colors.black), )), Container( margin: EdgeInsets.only(left: 60.w, right: 60.w), child: OutLineBtn( btnName: '保存到相册'.tr, onClick: () async { // 截图并保存到相册 try { final Color qrcodeStyleColor = defaultTargetPlatform == TargetPlatform.iOS ? const Color(0xFF000000) : Colors.white; final QrPainter painter = QrPainter( data: qrCodeUrl, version: QrVersions.auto, gapless: false, errorCorrectionLevel: QrErrorCorrectLevel.L, eyeStyle: QrEyeStyle( eyeShape: QrEyeShape.square, color: qrcodeStyleColor, ), dataModuleStyle: QrDataModuleStyle( dataModuleShape: QrDataModuleShape.square, color: qrcodeStyleColor, )); final ByteData? byteData = await painter.toImageData(600.0, format: ImageByteFormat.png); final Uint8List pngBytes = byteData!.buffer.asUint8List(); final result = await ImageGallerySaver.saveImage( Uint8List.fromList(pngBytes), quality: 100, name: 'qr_code'); if (result['isSuccess']) { EasyLoading.showToast('保存成功'.tr); } else { EasyLoading.showToast('保存失败'.tr); } } catch (e) { EasyLoading.showToast('保存失败'.tr); } }), ), SizedBox( height: 40.h, ) ], ), ), onPressed: () { Navigator.of(context).pop(); }, ), ), ], ); }, ); } // //邮件通知类型选择弹窗 // void emailNotifyTypeSlectAlert() { // showCupertinoDialog( // context: Get.context!, // builder: (BuildContext context) { // return CupertinoAlertDialog( // title: const Text('类型选择'), // content: Column( // children: [ // Padding( // padding: EdgeInsets.only( // left: 10.w, top: 8.h, bottom: 16.h, right: 10.w), // child: Align( // alignment: Alignment.centerLeft, // child: Text('请选择要使用哪种类型', style: TextStyle(fontSize: 20.sp)), // ), // ), // GestureDetector( // onTap: () { // setState(() { // isSystemEmailSelected = true; // }); // }, // child: Row( // mainAxisAlignment: MainAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.center, // children: [ // Image.asset( // isSystemEmailSelected // ? 'images/icon_round_select.png' // : 'images/icon_round_unSelect.png', // width: 30.w, // height: 30.w, // ), // Padding( // padding: EdgeInsets.only(left: 10.w), // child: Text( // '系统邮件(推荐)', // style: TextStyle( // fontSize: 22.sp, fontWeight: FontWeight.bold), // ), // ), // ], // ), // ), // Padding( // padding: EdgeInsets.only(top: 6.h, left: 10.w, bottom: 10.h), // child: Align( // alignment: Alignment.centerLeft, // child: Text( // '邮件将从软件平台直接发给用户,请根据需要在软件那里购买邮件数量', // style: TextStyle(fontSize: 18.sp), // textAlign: TextAlign.left, // ), // ), // ), // GestureDetector( // onTap: () { // setState(() { // isSystemEmailSelected = false; // }); // }, // child: Row( // mainAxisAlignment: MainAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.center, // children: [ // Image.asset( // !isSystemEmailSelected // ? 'images/icon_round_select.png' // : 'images/icon_round_unSelect.png', // width: 30.w, // height: 30.w, // ), // Padding( // padding: EdgeInsets.only(left: 10.w), // child: Text( // '个人邮件', // style: TextStyle( // fontSize: 22.sp, fontWeight: FontWeight.bold), // ), // ), // ], // ), // ), // Padding( // padding: EdgeInsets.only(top: 6.h, left: 10.w), // child: Align( // alignment: Alignment.centerLeft, // child: Text( // '邮件将从你的个人邮箱发给用户', // style: TextStyle(fontSize: 18.sp), // ), // ), // ), // ], // ), // actions: [ // CupertinoDialogAction( // onPressed: Get.back, // child: Text( // '确定'.tr, // style: TextStyle(color: AppColors.mainColor), // ), // ), // ], // ); // }, // ); // } }