From 8c0ae4f349113d4095bc345f1f846d5f8cb85d0c Mon Sep 17 00:00:00 2001 From: DaisyWu <18682150237@163.com> Date: Mon, 26 May 2025 15:58:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E9=97=AE=E9=A2=98-=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=92=A5=E5=8C=99=E5=90=84=E4=B8=AA=E7=B1=BB=E5=9E=8B=E4=B8=8B?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=80=9A=E8=AE=AF=E5=BD=95=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=8E=B7=E5=8F=96=E9=80=9A=E8=AE=AF=E5=BD=95?= =?UTF-8?q?=E8=81=94=E7=B3=BB=E4=BA=BA=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=8F=8A?= =?UTF-8?q?=E5=A7=93=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/sendElectronicKeyView_page.dart | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart b/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart index da455907..c6fc5cbe 100755 --- a/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart +++ b/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart @@ -163,8 +163,8 @@ class _SendElectronicKeyViewState extends State color: Colors.white, border: Border( bottom: BorderSide( - color: AppColors.greyLineColor, // 设置边框颜色 - width: 2.0.h, // 设置边框宽度 + color: AppColors.greyLineColor, + width: 2.0.h, ), )), child: Row( @@ -174,17 +174,14 @@ class _SendElectronicKeyViewState extends State Expanded( child: TextField( controller: logic.getCurrentController(1), - //输入框一行 maxLines: 1, inputFormatters: [ FilteringTextInputFormatter.deny('\n'), LengthLimitingTextInputFormatter(30), ], - // controller: _controller, autofocus: false, textAlign: TextAlign.end, decoration: InputDecoration( - //输入里面输入文字内边距设置 hintText: rightTitle, hintStyle: TextStyle(fontSize: 22.sp), focusedBorder: const OutlineInputBorder( @@ -205,9 +202,7 @@ class _SendElectronicKeyViewState extends State fontSize: 22.sp, textBaseline: TextBaseline.alphabetic), ), ), - SizedBox( - width: 10.w, - ), + SizedBox(width: 10.w), Container( width: 32.w, height: 32.w, @@ -222,22 +217,48 @@ class _SendElectronicKeyViewState extends State onTap: () async { final Contact? currentContact = await logic.state.contactPicker.selectContact(); - logic.state.contact = currentContact!; - if (currentContact.phoneNumbers!.isNotEmpty) { - logic.state.emailOrPhoneController.text = currentContact - .phoneNumbers![0] - .replaceAll(RegExp(r'\s+\b|\b\s'), ''); - } - if (currentContact.fullName!.isNotEmpty) { - logic.state.keyNameController.text = - currentContact.fullName!; + if (currentContact != null) { + logic.state.contact = currentContact; + + // 处理手机号 + if (currentContact.phoneNumbers != null && + currentContact.phoneNumbers!.isNotEmpty) { + // 获取第一个手机号并清理格式 + String phoneNumber = currentContact.phoneNumbers![0]; + // 移除所有空格、括号、连字符等特殊字符 + phoneNumber = + phoneNumber.replaceAll(RegExp(r'[\s\(\)\-]'), ''); + // 如果号码以+开头,保留+号 + if (phoneNumber.startsWith('+')) { + phoneNumber = '+' + + phoneNumber + .substring(1) + .replaceAll(RegExp(r'[^\d]'), ''); + } else { + phoneNumber = + phoneNumber.replaceAll(RegExp(r'[^\d]'), ''); + } + logic.state.emailOrPhoneController.text = phoneNumber; + } else { + logic.state.emailOrPhoneController.text = ''; + } + + // 处理姓名 + if (currentContact.fullName != null && + currentContact.fullName!.isNotEmpty) { + logic.state.keyNameController.text = + currentContact.fullName!; + } + + // 更新UI + logic.update(); } }, ), ), Container( - color: AppColors.greyLineColor, // 设置边框颜色 - height: 2.0.h, // + color: AppColors.greyLineColor, + height: 2.0.h, ) ], ),