import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/main/lockDetail/messageWarn/addFamily/addFamily_logic.dart'; import 'package:star_lock/main/lockDetail/messageWarn/addFamily/addFamily_state.dart'; import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; import 'package:star_lock/tools/commonItem.dart'; import 'package:star_lock/tools/showCupertinoAlertView.dart'; import 'package:star_lock/tools/showTFView.dart'; import 'package:star_lock/tools/storage.dart'; import 'package:star_lock/tools/submitBtn.dart'; import '../../../../../app_settings/app_colors.dart'; import '../../../../../tools/titleAppBar.dart'; class AddFamilyPage extends StatefulWidget { const AddFamilyPage({Key? key}) : super(key: key); @override State createState() => _AddFamilyPageState(); } class _AddFamilyPageState extends State { final AddFamilyLogic logic = Get.put(AddFamilyLogic()); final AddFamilyState state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: state.isDetail.value ? '家人详情'.tr : '添加家人'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: Container( padding: EdgeInsets.all(30.w), child: Column( children: [ Obx(() => CommonItem( leftTitel: '开门方式'.tr, rightTitle: state.isDetail.value ? logic.getKeyTypeStr() : state.lockUserKeys.value.currentKeyTypeStr ?? '请选择'.tr, isHaveLine: true, isHaveDirection: true, action: () { //锁用户 Get.toNamed(Routers.lockUserPage, arguments: { 'getLockId': state.getLockId.value, 'openDoorId': state.openDoorId.value, })?.then((val) { if (val != null) { state.lockUserKeys.value = val; if (state.isDetail.value) { logic.updateLockNoticeSetting(); } } }); })), Obx(() => CommonItem( leftTitel: '家人'.tr, rightTitle: state.lockUserKeys.value.currentKeyName, isHaveLine: true, isHaveRightWidget: state.isDetail.value ? false : true, isHaveDirection: false, rightWidget: getFamilyWidget('请输入'.tr), action: () { if (state.isDetail.value == true) { showCupertinoAlertDialog(); } }, )), SizedBox( height: 20.h, ), GestureDetector( onTap: () { Get.toNamed(Routers.notificationModePage, arguments: { 'familyData': state.familyData.value })?.then((val) { if (val != null) { state.emailListStr.value = logic.getEmailListStr(val); state.phontListStr.value = logic.getPhoneListStr(val); } }); }, child: Container( color: Colors.white, margin: EdgeInsets.only(bottom: 10.h), child: Column( children: [ CommonItem( leftTitel: '提醒方式'.tr, rightTitle: '', isHaveLine: false, isHaveRightWidget: false, isHaveDirection: true, ), _buildNotifyContain('APP推送'.tr, '管理员'.tr), Obx(() => state.emailListStr.value.isNotEmpty ? _buildNotifyContain( '邮件提醒'.tr, state.emailListStr.value) : Container()), Obx(() => state.phontListStr.value.isNotEmpty ? _buildNotifyContain( '短信提醒'.tr, state.phontListStr.value) : Container()), ], ), ), ), Expanded( child: SizedBox( height: 40.h, )), Obx(() => SubmitBtn( btnName: state.isDetail.value == true ? '删除'.tr : '保存'.tr, isDisabled: state.isDetail.value == true ? true : logic.checkBtnDisable(), isDelete: state.isDetail.value, onClick: () async { final bool? isVip = await Storage.getBool(saveIsVip); if (isVip == true) { if (state.isDetail.value) { logic.deleteLockNoticeSetting(); } else { logic.addLockNoticeSetting(); } } else { ShowCupertinoAlertView().advancedFeatureAlert(); } }, )), SizedBox( height: 60.h, ) ], ), ), ); } Widget _buildNotifyContain(String notifyTitle, String notifyContent) { return Container( padding: EdgeInsets.only(left: 10.w, right: 10.w, top: 12.h, bottom: 12.h), margin: EdgeInsets.only(bottom: 20.h, top: 10.h, left: 20.w, right: 20.w), decoration: BoxDecoration( color: AppColors.mainBackgroundColor, borderRadius: BorderRadius.circular(6.0.w), ), child: Row( children: [ Text( notifyTitle, style: TextStyle(color: Colors.black, fontSize: 20.sp), ), Expanded( child: SizedBox( width: 20.w, )), Text(notifyContent, textAlign: TextAlign.end, style: TextStyle( color: AppColors.placeholderTextColor, fontSize: 20.sp)), ], ), ); } //修改家人名称弹窗 void showCupertinoAlertDialog() { showDialog( context: context, builder: (BuildContext context) { return ShowTFView( title: '修改名字'.tr, tipTitle: '请输入'.tr, controller: state.changeNameController, inputFormatters: [ FilteringTextInputFormatter.deny('\n'), LengthLimitingTextInputFormatter(50), ], sureClick: () { //发送编辑钥匙名称请求 if (state.changeNameController.text.isNotEmpty) { logic.updateLockNoticeSetting(); } else { logic.showToast('请输入'.tr); } }, cancelClick: () { Navigator.pop(context); }, ); }, ); } // 接受者信息输入框 Widget getFamilyWidget(String tfStr) { final TextEditingController emailController = TextEditingController(); emailController.text = state.lockUserKeys.value.currentKeyName ?? ''; return SizedBox( height: 50.h, width: 360.w, child: Row( children: [ Expanded( child: TextField( controller: emailController, //输入框一行 maxLines: 1, inputFormatters: [ FilteringTextInputFormatter.deny('\n'), LengthLimitingTextInputFormatter(30), ], autofocus: false, textAlign: TextAlign.end, decoration: InputDecoration( hintText: tfStr, hintStyle: TextStyle(fontSize: 22.sp), focusedBorder: const OutlineInputBorder( borderSide: BorderSide(width: 0, color: Colors.transparent)), disabledBorder: const OutlineInputBorder( borderSide: BorderSide(width: 0, color: Colors.transparent)), enabledBorder: const OutlineInputBorder( borderSide: BorderSide(width: 0, color: Colors.transparent)), border: const OutlineInputBorder( borderSide: BorderSide(width: 0, color: Colors.transparent)), contentPadding: const EdgeInsets.symmetric(vertical: 0), ), style: TextStyle( fontSize: 22.sp, textBaseline: TextBaseline.alphabetic), onChanged: (String value) { state.lockUserKeys.value.currentKeyName = value; state.lockUserKeys.refresh(); }, ), ), ], ), ); } }