import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/app_settings/app_colors.dart'; import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; typedef AuthInfoCallback = void Function(String? idCard, String? name); class ShowCupertinoAlertView { //微信公众号二维码弹窗 void showQRImageAlert(BuildContext widgetContext, String qrCodeUrl) { showCupertinoModalPopup( context: widgetContext, builder: (context) { return CupertinoActionSheet( actions: [ Container( color: Colors.white, // 设置底色为白色 child: CupertinoActionSheetAction( child: Container( margin: const EdgeInsets.all(0), child: Column( children: [ SizedBox( height: 60.h, ), Image.network( qrCodeUrl, width: 400.w, height: 400.w, ), SizedBox( height: 20.h, ), Padding( padding: EdgeInsets.only(left: 60.w, right: 60.w), child: Text( '开启微信接收报警消息需要先关注斯凯智能锁微信公众号,请保存二维码并使用微信扫一扫设置'.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, child: Row( children: [ 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), )), ), 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: const Text('实名认证为付费功能,请联系锁的管理员购买后再使用'), 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(); }, ), ], ); }, ); } }