From f10963a172a719bae931785963e232745268f17c Mon Sep 17 00:00:00 2001 From: czz <862977248@qq.com> Date: Tue, 15 Jul 2025 15:46:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/mh_page/bluetooth.dart | 80 ++++++++++++------- .../device/mht_bind_device_success.dart | 65 ++++++++------- 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/lib/pages/mh_page/bluetooth.dart b/lib/pages/mh_page/bluetooth.dart index 045e587..a51e9b9 100644 --- a/lib/pages/mh_page/bluetooth.dart +++ b/lib/pages/mh_page/bluetooth.dart @@ -28,36 +28,36 @@ class _BluetoothPageState extends State { void initState() { super.initState(); obsData = Map.from(widget.data).obs; // 复制成 obs - String text; + // String text; - if (widget.data.containsKey('name') && - widget.data['name'] != null && - widget.data['name'].toString().isNotEmpty) { - text = widget.data['name'].toString(); - } else { - text = '未命名'.tr; - } + // if (obsData.containsKey('name') && + // obsData['name'] != null && + // obsData['name'].toString().isNotEmpty) { + // text = obsData['name'].toString(); + // } else { + // text = '未命名'.tr; + // } - _calculateTextHalfWidth(text); + // _calculateTextHalfWidth(text); } - void _calculateTextHalfWidth(String text) { - final textSpan = TextSpan( - text: text, - style: TextStyle( - fontSize: 40.rpx, - height: 1, - ), - ); - final textPainter = TextPainter( - text: textSpan, - textDirection: ui.TextDirection.ltr, - ); - textPainter.layout(); // 计算文本宽度 - setState(() { - _textHalfWidth = textPainter.width / 2; - }); - } + // void _calculateTextHalfWidth(String text) { + // final textSpan = TextSpan( + // text: text, + // style: TextStyle( + // fontSize: 40.rpx, + // height: 1, + // ), + // ); + // final textPainter = TextPainter( + // text: textSpan, + // textDirection: ui.TextDirection.ltr, + // ); + // textPainter.layout(); // 计算文本宽度 + // setState(() { + // _textHalfWidth = textPainter.width / 2; + // }); + // } BoxConstraints? bodysize; DeviceListController deviceListController = Get.find(); @@ -133,11 +133,14 @@ class _BluetoothPageState extends State { maxLines: 1, // 限制为单行 ), Positioned( - left: - MediaQuery.of(context).size.width / - 2 + - _textHalfWidth + - 22.rpx, + left: MediaQuery.of(context) + .size + .width / + 2 + + _calculateTextHalfWidth( + obsData['name']?.toString() ?? + '未命名') + + 22.rpx, top: 5.rpx, child: ClickableContainer( backgroundColor: Colors.transparent, @@ -425,3 +428,18 @@ class _BluetoothPageState extends State { ); } } + +double _calculateTextHalfWidth(String text) { + final textPainter = TextPainter( + text: TextSpan( + text: text, + style: TextStyle( + fontSize: 40.rpx, + height: 1, + ), + ), + textDirection: ui.TextDirection.ltr, + ); + textPainter.layout(); + return textPainter.width / 2; +} diff --git a/lib/pages/mh_page/device/mht_bind_device_success.dart b/lib/pages/mh_page/device/mht_bind_device_success.dart index ca88612..e1d19a6 100644 --- a/lib/pages/mh_page/device/mht_bind_device_success.dart +++ b/lib/pages/mh_page/device/mht_bind_device_success.dart @@ -16,6 +16,7 @@ import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; import 'package:vbvs_app/controller/person/person_controller.dart'; import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; import 'package:vbvs_app/controller/user_info_controller.dart'; +import 'package:vbvs_app/pages/mh_page/device/model/BlueToothDataModel.dart'; import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart'; class MHTBindDeviceSuccess extends StatefulWidget { @@ -241,39 +242,43 @@ class _MHTBindDeviceSuccessState extends State { borderRadius: AppConstants().normal_container_radius, // 圆角半径 onTap: () async { - var data = blueteethBindController.shareDevice; - // TopSlideNotification.show( - // context, - // text: "功能开发中...", - // ); - // return; - PersonController personController = Get.find(); - String deviceID = - personController.currentPersonId.value; + Map editeData; + BlueToothDataModel data = + blueteethBindController.shareDevice; + editeData = {"mac": data.mac}; + Get.toNamed("/deviceSharePage", arguments: editeData); + // // TopSlideNotification.show( + // // context, + // // text: "功能开发中...", + // // ); + // // return; + // PersonController personController = Get.find(); + // String deviceID = + // personController.currentPersonId.value; - BodyDeviceController bodyDeviceController = - Get.find(); - await bodyDeviceController.getDeviceList(); - List deviceList = - bodyDeviceController.deviceList.value; + // BodyDeviceController bodyDeviceController = + // Get.find(); + // await bodyDeviceController.getDeviceList(); + // List deviceList = + // bodyDeviceController.deviceList.value; - if (deviceList != null && deviceList.isNotEmpty) { - // 查找第一个 _id 匹配的设备 - final matchedDevice = deviceList.firstWhere( - (element) => element['_id'] == deviceID, - orElse: () => null, - ); + // if (deviceList != null && deviceList.isNotEmpty) { + // // 查找第一个 _id 匹配的设备 + // final matchedDevice = deviceList.firstWhere( + // (element) => element['_id'] == deviceID, + // orElse: () => null, + // ); - if (matchedDevice != null) { - // 跳转并传入设备 - Get.toNamed("/deviceSharePage", - arguments: matchedDevice); - } else { - print("未找到匹配的设备"); - } - } else { - print("设备列表为空"); - } + // if (matchedDevice != null) { + // // 跳转并传入设备 + // Get.toNamed("/deviceSharePage", + // arguments: matchedDevice); + // } else { + // print("未找到匹配的设备"); + // } + // } else { + // print("设备列表为空"); + // } }, colors: AppConstants().mhtButtongradientColors, gradientDirection: GradientDirection.vertical,