立即分享

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() {
super.initState();
obsData = Map<String, dynamic>.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,10 +133,13 @@ class _BluetoothPageState extends State<BluetoothPage> {
maxLines: 1, // 限制为单行
),
Positioned(
left:
MediaQuery.of(context).size.width /
left: MediaQuery.of(context)
.size
.width /
2 +
_textHalfWidth +
_calculateTextHalfWidth(
obsData['name']?.toString() ??
'未命名') +
22.rpx,
top: 5.rpx,
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/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<MHTBindDeviceSuccess> {
borderRadius:
AppConstants().normal_container_radius, // 圆角半径
onTap: () async {
var data = blueteethBindController.shareDevice;
// TopSlideNotification.show(
// context,
// text: "功能开发中...",
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;
// 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 =
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 (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,