立即分享
This commit is contained in:
@@ -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) {
|
// void _calculateTextHalfWidth(String text) {
|
||||||
final textSpan = TextSpan(
|
// final textSpan = TextSpan(
|
||||||
text: text,
|
// text: text,
|
||||||
style: TextStyle(
|
// style: TextStyle(
|
||||||
fontSize: 40.rpx,
|
// fontSize: 40.rpx,
|
||||||
height: 1,
|
// height: 1,
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
final textPainter = TextPainter(
|
// final textPainter = TextPainter(
|
||||||
text: textSpan,
|
// text: textSpan,
|
||||||
textDirection: ui.TextDirection.ltr,
|
// textDirection: ui.TextDirection.ltr,
|
||||||
);
|
// );
|
||||||
textPainter.layout(); // 计算文本宽度
|
// textPainter.layout(); // 计算文本宽度
|
||||||
setState(() {
|
// setState(() {
|
||||||
_textHalfWidth = textPainter.width / 2;
|
// _textHalfWidth = textPainter.width / 2;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
BoxConstraints? bodysize;
|
BoxConstraints? bodysize;
|
||||||
DeviceListController deviceListController = Get.find();
|
DeviceListController deviceListController = Get.find();
|
||||||
@@ -133,11 +133,14 @@ class _BluetoothPageState extends State<BluetoothPage> {
|
|||||||
maxLines: 1, // 限制为单行
|
maxLines: 1, // 限制为单行
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
left:
|
left: MediaQuery.of(context)
|
||||||
MediaQuery.of(context).size.width /
|
.size
|
||||||
2 +
|
.width /
|
||||||
_textHalfWidth +
|
2 +
|
||||||
22.rpx,
|
_calculateTextHalfWidth(
|
||||||
|
obsData['name']?.toString() ??
|
||||||
|
'未命名') +
|
||||||
|
22.rpx,
|
||||||
top: 5.rpx,
|
top: 5.rpx,
|
||||||
child: ClickableContainer(
|
child: ClickableContainer(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
// return;
|
// // TopSlideNotification.show(
|
||||||
PersonController personController = Get.find();
|
// // context,
|
||||||
String deviceID =
|
// // text: "功能开发中...",
|
||||||
personController.currentPersonId.value;
|
// // );
|
||||||
|
// // return;
|
||||||
|
// PersonController personController = Get.find();
|
||||||
|
// String deviceID =
|
||||||
|
// personController.currentPersonId.value;
|
||||||
|
|
||||||
BodyDeviceController bodyDeviceController =
|
// BodyDeviceController bodyDeviceController =
|
||||||
Get.find();
|
// Get.find();
|
||||||
await bodyDeviceController.getDeviceList();
|
// await bodyDeviceController.getDeviceList();
|
||||||
List deviceList =
|
// List deviceList =
|
||||||
bodyDeviceController.deviceList.value;
|
// bodyDeviceController.deviceList.value;
|
||||||
|
|
||||||
if (deviceList != null && deviceList.isNotEmpty) {
|
// if (deviceList != null && deviceList.isNotEmpty) {
|
||||||
// 查找第一个 _id 匹配的设备
|
// // 查找第一个 _id 匹配的设备
|
||||||
final matchedDevice = deviceList.firstWhere(
|
// final matchedDevice = deviceList.firstWhere(
|
||||||
(element) => element['_id'] == deviceID,
|
// (element) => element['_id'] == deviceID,
|
||||||
orElse: () => null,
|
// orElse: () => null,
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (matchedDevice != null) {
|
// if (matchedDevice != null) {
|
||||||
// 跳转并传入设备
|
// // 跳转并传入设备
|
||||||
Get.toNamed("/deviceSharePage",
|
// Get.toNamed("/deviceSharePage",
|
||||||
arguments: matchedDevice);
|
// arguments: matchedDevice);
|
||||||
} else {
|
// } else {
|
||||||
print("未找到匹配的设备");
|
// print("未找到匹配的设备");
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
print("设备列表为空");
|
// print("设备列表为空");
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
colors: AppConstants().mhtButtongradientColors,
|
colors: AppConstants().mhtButtongradientColors,
|
||||||
gradientDirection: GradientDirection.vertical,
|
gradientDirection: GradientDirection.vertical,
|
||||||
|
|||||||
Reference in New Issue
Block a user