立即分享

This commit is contained in:
czz
2025-07-15 15:46:29 +08:00
parent 8fae793f61
commit f10963a172
2 changed files with 84 additions and 61 deletions

View File

@@ -28,36 +28,36 @@ class _BluetoothPageState extends State<BluetoothPage> {
void initState() { void initState() {
super.initState(); super.initState();
obsData = Map<String, dynamic>.from(widget.data).obs; // 复制成 obs obsData = Map<String, dynamic>.from(widget.data).obs; // 复制成 obs
String text; // String text;
if (widget.data.containsKey('name') && // if (obsData.containsKey('name') &&
widget.data['name'] != null && // obsData['name'] != null &&
widget.data['name'].toString().isNotEmpty) { // obsData['name'].toString().isNotEmpty) {
text = widget.data['name'].toString(); // text = obsData['name'].toString();
} else { // } else {
text = '未命名'.tr; // text = '未命名'.tr;
// }
// _calculateTextHalfWidth(text);
} }
_calculateTextHalfWidth(text); // void _calculateTextHalfWidth(String text) {
} // final textSpan = TextSpan(
// text: text,
void _calculateTextHalfWidth(String text) { // style: TextStyle(
final textSpan = TextSpan( // fontSize: 40.rpx,
text: text, // height: 1,
style: TextStyle( // ),
fontSize: 40.rpx, // );
height: 1, // final textPainter = TextPainter(
), // text: textSpan,
); // textDirection: ui.TextDirection.ltr,
final textPainter = TextPainter( // );
text: textSpan, // textPainter.layout(); // 计算文本宽度
textDirection: ui.TextDirection.ltr, // setState(() {
); // _textHalfWidth = textPainter.width / 2;
textPainter.layout(); // 计算文本宽度 // });
setState(() { // }
_textHalfWidth = textPainter.width / 2;
});
}
BoxConstraints? bodysize; BoxConstraints? bodysize;
DeviceListController deviceListController = Get.find(); DeviceListController deviceListController = Get.find();
@@ -133,10 +133,13 @@ class _BluetoothPageState extends State<BluetoothPage> {
maxLines: 1, // 限制为单行 maxLines: 1, // 限制为单行
), ),
Positioned( Positioned(
left: left: MediaQuery.of(context)
MediaQuery.of(context).size.width / .size
.width /
2 + 2 +
_textHalfWidth + _calculateTextHalfWidth(
obsData['name']?.toString() ??
'未命名') +
22.rpx, 22.rpx,
top: 5.rpx, top: 5.rpx,
child: ClickableContainer( child: ClickableContainer(
@@ -425,3 +428,18 @@ class _BluetoothPageState extends State<BluetoothPage> {
); );
} }
} }
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;
}

View File

@@ -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/person/person_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/controller/user_info_controller.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'; import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
class MHTBindDeviceSuccess extends StatefulWidget { class MHTBindDeviceSuccess extends StatefulWidget {
@@ -241,39 +242,43 @@ class _MHTBindDeviceSuccessState extends State<MHTBindDeviceSuccess> {
borderRadius: borderRadius:
AppConstants().normal_container_radius, // 圆角半径 AppConstants().normal_container_radius, // 圆角半径
onTap: () async { onTap: () async {
var data = blueteethBindController.shareDevice; Map editeData;
// TopSlideNotification.show( BlueToothDataModel data =
// context, blueteethBindController.shareDevice;
// text: "功能开发中...", 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;
// if (deviceList != null && deviceList.isNotEmpty) {
// // 查找第一个 _id 匹配的设备
// final matchedDevice = deviceList.firstWhere(
// (element) => element['_id'] == deviceID,
// orElse: () => null,
// ); // );
// return;
PersonController personController = Get.find();
String deviceID =
personController.currentPersonId.value;
BodyDeviceController bodyDeviceController = // if (matchedDevice != null) {
Get.find(); // // 跳转并传入设备
await bodyDeviceController.getDeviceList(); // Get.toNamed("/deviceSharePage",
List deviceList = // arguments: matchedDevice);
bodyDeviceController.deviceList.value; // } else {
// print("未找到匹配的设备");
if (deviceList != null && deviceList.isNotEmpty) { // }
// 查找第一个 _id 匹配的设备 // } else {
final matchedDevice = deviceList.firstWhere( // print("设备列表为空");
(element) => element['_id'] == deviceID, // }
orElse: () => null,
);
if (matchedDevice != null) {
// 跳转并传入设备
Get.toNamed("/deviceSharePage",
arguments: matchedDevice);
} else {
print("未找到匹配的设备");
}
} else {
print("设备列表为空");
}
}, },
colors: AppConstants().mhtButtongradientColors, colors: AppConstants().mhtButtongradientColors,
gradientDirection: GradientDirection.vertical, gradientDirection: GradientDirection.vertical,