设备名称 人员名称 显示长度限制

This commit is contained in:
czz
2025-08-05 17:55:12 +08:00
parent 00215e99d2
commit 16a304cae8
5 changed files with 312 additions and 219 deletions

View File

@@ -2,6 +2,7 @@ import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
@@ -89,57 +90,109 @@ class _BluetoothPageState extends State<BluetoothPage> {
children: [
Column(
children: [
Container(
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: [
Text(
obsData['name']?.toString() ??
getNameByType(obsData.value),
style: TextStyle(
color: Colors.white,
fontSize: 40.rpx,
Padding(
padding:
EdgeInsets.symmetric(horizontal: 30.rpx),
child: Container(
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
_limitText(
obsData['name']?.toString() ??
getNameByType(obsData.value),
AppConstants().text_length),
style: TextStyle(
color: Colors.white,
fontSize: 40.rpx,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
textAlign: TextAlign.center,
),
),
overflow:
TextOverflow.ellipsis, // 超出部分显示省略号
maxLines: 1, // 限制为单行
),
Positioned(
left: MediaQuery.of(context)
.size
.width /
2 +
_calculateTextHalfWidth(
obsData['name']?.toString() ??
getNameByType(
obsData.value)) +
22.rpx,
top: 5.rpx,
child: ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor:
const Color(0xFF055466),
padding: EdgeInsets.only(left: 0),
onTap: () async {
var x = await Get.toNamed(
"/editBedPage",
arguments: obsData);
if (x != null) {
setState(() {
obsData
.addAll(x); // 值更新后主动刷新页面
});
}
},
child: Container(
width: 42.rpx,
height: 42.rpx,
child: SvgPicture.asset(
"assets/img/icon/bluetooth_edit.svg",
color: Colors.white,
))))
],
SizedBox(width: 10.rpx),
ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor: const Color(0xFF055466),
padding: EdgeInsets.zero,
onTap: () async {
var x = await Get.toNamed(
"/editBedPage",
arguments: obsData);
if (x != null) {
setState(() {
obsData.addAll(x);
});
}
},
child: SizedBox(
width: 42.rpx,
height: 42.rpx,
child: SvgPicture.asset(
"assets/img/icon/bluetooth_edit.svg",
color: Colors.white,
),
),
),
],
),
// Stack(
// alignment: Alignment.center,
// children: [
// Text(
// obsData['name']?.toString() ??
// getNameByType(obsData.value),
// style: TextStyle(
// color: Colors.white,
// fontSize: 40.rpx,
// ),
// overflow:
// TextOverflow.ellipsis, // 超出部分显示省略号
// maxLines: 1, // 限制为单行
// ),
// Positioned(
// left: MediaQuery.of(context)
// .size
// .width /
// 2 +
// _calculateTextHalfWidth(
// obsData['name']?.toString() ??
// getNameByType(
// obsData.value)) +
// 22.rpx,
// top: 5.rpx,
// child: ClickableContainer(
// backgroundColor:
// Colors.transparent,
// highlightColor:
// const Color(0xFF055466),
// padding: EdgeInsets.only(left: 0),
// onTap: () async {
// var x = await Get.toNamed(
// "/editBedPage",
// arguments: obsData);
// if (x != null) {
// setState(() {
// obsData.addAll(
// x); // 值更新后主动刷新页面
// });
// }
// },
// child: Container(
// width: 42.rpx,
// height: 42.rpx,
// child: SvgPicture.asset(
// "assets/img/icon/bluetooth_edit.svg",
// color: Colors.white,
// ))))
// ],
// ),
),
),
@@ -239,23 +292,6 @@ class _BluetoothPageState extends State<BluetoothPage> {
: '删除'.tr,
"",
onTap: () async {
// await deviceListController
// .unbindDevice(obsData);
// await deviceListController
// .getDeviceList();
// MHTHomeController homeController =
// Get.find();
// homeController.selectDevcie.value = "";
// try {
// WebviewTestController
// webviewTestController = Get.find();
// webviewTestController.web.jsbridge?.dart
// .unBindDevice();
// } catch (e) {
// ef.log("[h5]通知列表更新报错:$e");
// }
// Get.toNamed("/mianPageBottomChange");
if (obsData['bind_type'] == 1) {
// 解绑弹窗
showUnbindConfirmDialog(
@@ -439,19 +475,24 @@ class _BluetoothPageState extends State<BluetoothPage> {
),
);
}
String _limitText(String? text, int maxLength) {
if (text == null || text.length <= maxLength) return text ?? '';
return text.substring(0, maxLength) + '...';
}
}
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;
}
// 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;
// }