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

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

@@ -167,13 +167,14 @@ class _MessageWidgetWidgetState extends State<MessageWidgetWidget> {
child: Align( child: Align(
alignment: AlignmentDirectional(-1, 0), alignment: AlignmentDirectional(-1, 0),
child: Text( child: Text(
label.tr,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 1,
label.tr,
style: TextStyle( style: TextStyle(
fontFamily: 'Inter', fontFamily: 'Inter',
fontSize: 26.rpx, fontSize: 26.rpx,
letterSpacing: 0.0, letterSpacing: 0.0,
height: 1,
color: themeController.currentColor.sc4, color: themeController.currentColor.sc4,
), ),
), ),
@@ -189,13 +190,14 @@ class _MessageWidgetWidgetState extends State<MessageWidgetWidget> {
child: Align( child: Align(
alignment: AlignmentDirectional(-1, 0), alignment: AlignmentDirectional(-1, 0),
child: Text( child: Text(
"${value}",
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 1,
"${value}",
style: TextStyle( style: TextStyle(
fontFamily: 'Inter', fontFamily: 'Inter',
fontSize: 26.rpx, fontSize: 26.rpx,
letterSpacing: 0.0, letterSpacing: 0.0,
height: 1,
color: themeController.currentColor.sc3, color: themeController.currentColor.sc3,
), ),
), ),

View File

@@ -2,6 +2,7 @@ import 'package:ef/ef.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.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/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart'; import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart'; import 'package:vbvs_app/component/tool/ClickableContainer.dart';
@@ -89,57 +90,109 @@ class _BluetoothPageState extends State<BluetoothPage> {
children: [ children: [
Column( Column(
children: [ children: [
Container( Padding(
width: double.infinity, padding:
child: Stack( EdgeInsets.symmetric(horizontal: 30.rpx),
alignment: Alignment.center, child: Container(
children: [ width: double.infinity,
Text( child: Row(
obsData['name']?.toString() ?? mainAxisAlignment: MainAxisAlignment.center,
getNameByType(obsData.value), mainAxisSize: MainAxisSize.min,
style: TextStyle( children: [
color: Colors.white, Flexible(
fontSize: 40.rpx, 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: SizedBox(width: 10.rpx),
TextOverflow.ellipsis, // 超出部分显示省略号 ClickableContainer(
maxLines: 1, // 限制为单行 backgroundColor: Colors.transparent,
), highlightColor: const Color(0xFF055466),
Positioned( padding: EdgeInsets.zero,
left: MediaQuery.of(context) onTap: () async {
.size var x = await Get.toNamed(
.width / "/editBedPage",
2 + arguments: obsData);
_calculateTextHalfWidth( if (x != null) {
obsData['name']?.toString() ?? setState(() {
getNameByType( obsData.addAll(x);
obsData.value)) + });
22.rpx, }
top: 5.rpx, },
child: ClickableContainer( child: SizedBox(
backgroundColor: Colors.transparent, width: 42.rpx,
highlightColor: height: 42.rpx,
const Color(0xFF055466), child: SvgPicture.asset(
padding: EdgeInsets.only(left: 0), "assets/img/icon/bluetooth_edit.svg",
onTap: () async { color: Colors.white,
var x = await Get.toNamed( ),
"/editBedPage", ),
arguments: obsData); ),
if (x != null) { ],
setState(() { ),
obsData // Stack(
.addAll(x); // 值更新后主动刷新页面 // alignment: Alignment.center,
}); // children: [
} // Text(
}, // obsData['name']?.toString() ??
child: Container( // getNameByType(obsData.value),
width: 42.rpx,
height: 42.rpx, // style: TextStyle(
child: SvgPicture.asset( // color: Colors.white,
"assets/img/icon/bluetooth_edit.svg", // fontSize: 40.rpx,
color: Colors.white, // ),
)))) // 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, : '删除'.tr,
"", "",
onTap: () async { 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) { if (obsData['bind_type'] == 1) {
// 解绑弹窗 // 解绑弹窗
showUnbindConfirmDialog( 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) { // double _calculateTextHalfWidth(String text) {
final textPainter = TextPainter( // final textPainter = TextPainter(
text: TextSpan( // text: TextSpan(
text: text, // text: text,
style: TextStyle( // style: TextStyle(
fontSize: 40.rpx, // fontSize: 40.rpx,
height: 1, // height: 1,
), // ),
), // ),
textDirection: ui.TextDirection.ltr, // textDirection: ui.TextDirection.ltr,
); // );
textPainter.layout(); // textPainter.layout();
return textPainter.width / 2; // return textPainter.width / 2;
} // }

View File

@@ -210,12 +210,6 @@ class _EditBedPageState extends State<EditBedPage> {
textAlign: TextAlign.center, textAlign: TextAlign.center,
textAlignVertical: textAlignVertical:
TextAlignVertical.center, TextAlignVertical.center,
maxLength: AppConstants().text_length,
buildCounter: (_,
{int? currentLength,
bool? isFocused,
int? maxLength}) =>
null,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "请输入设备的名称".tr, hintText: "请输入设备的名称".tr,
contentPadding: contentPadding:
@@ -262,101 +256,16 @@ class _EditBedPageState extends State<EditBedPage> {
letterSpacing: 0, letterSpacing: 0,
), ),
cursorColor: Colors.white, cursorColor: Colors.white,
), // ✅ 允许横向滚动防止溢出:
keyboardType: TextInputType.text,
// 自定义右下角计数器 maxLines: 1,
Positioned( scrollPadding: EdgeInsets.zero,
bottom: 2.rpx, enableInteractiveSelection: true,
right: 10.rpx, expands: false,
child: Text(
'${_nameController.text.characters.length} / ${AppConstants().text_length}',
style: TextStyle(
fontSize: 24.rpx,
color: const Color(0xFF929699),
fontFamily: 'Readex Pro',
),
),
), ),
], ],
), ),
), ),
// Container(
// alignment: Alignment.center,
// height: bodysize!.maxHeight * 0.076,
// decoration: const BoxDecoration(
// border: Border(
// bottom: BorderSide(
// color: Color(0xFF929699),
// width: 0))),
// child: TextFormField(
// // autofocus: true,
// controller: _nameController,
// obscureText: false,
// onChanged: (val) {
// editedData['name'] = val;
// },
// textAlign: TextAlign.center,
// maxLength: AppConstants().text_length,
// decoration: InputDecoration(
// hintText: "请输入设备的名称".tr,
// contentPadding:
// const EdgeInsetsDirectional
// .fromSTEB(10, 0, 10, 0),
// labelStyle: TextStyle(
// fontFamily: 'Readex Pro',
// letterSpacing: 0,
// fontSize: 36.rpx, // 设置输入文字大小
// color: Colors.white, // 设置输入文字颜色
// ),
// hintStyle: TextStyle(
// fontFamily: 'Readex Pro',
// letterSpacing: 0,
// color: Color(0xFF929699),
// fontSize: 36.rpx,
// ),
// enabledBorder: UnderlineInputBorder(
// borderSide: const BorderSide(
// color: Color(0x00000000),
// width: 2,
// ),
// borderRadius:
// BorderRadius.circular(8),
// ),
// focusedBorder: UnderlineInputBorder(
// borderSide: const BorderSide(
// color: Color(0x00000000),
// width: 2,
// ),
// borderRadius:
// BorderRadius.circular(8),
// ),
// errorBorder: UnderlineInputBorder(
// borderSide: const BorderSide(
// color: Color(0x00000000),
// width: 2,
// ),
// borderRadius:
// BorderRadius.circular(8),
// ),
// focusedErrorBorder:
// UnderlineInputBorder(
// borderSide: const BorderSide(
// color: Color(0x00000000),
// width: 2,
// ),
// borderRadius:
// BorderRadius.circular(8),
// ),
// ),
// style: TextStyle(
// fontFamily: 'Readex Pro',
// letterSpacing: 0,
// color: Colors.white,
// fontSize: 36.rpx,
// ),
// ),
// )
) )
], ],
), ),

View File

@@ -117,7 +117,7 @@ class _MinePageState extends State<NewMinePage> {
child: Row( child: Row(
children: [ children: [
Obx(() { Obx(() {
userInfoController.model.login!; userInfoController.model.login!;
return Container( return Container(
width: 120.rpx, width: 120.rpx,
height: 120.rpx, height: 120.rpx,
@@ -151,12 +151,29 @@ class _MinePageState extends State<NewMinePage> {
children: [ children: [
Row( Row(
children: [ children: [
// Text(
// login == 1
// ? (userInfoController
// .model.user!.nick_name ??
// '未命名'.tr)
// : "未命名".tr,
// style: TextStyle(
// fontFamily: 'Inter',
// color: themeController.currentColor.sc3,
// fontSize:
// AppConstants().title_text_fontSize,
// letterSpacing: 0.0,
// ),
// ),
Text( Text(
login == 1 limitText(
? (userInfoController login == 1
.model.user!.nick_name ?? ? userInfoController
'未命名'.tr) .model.user?.nick_name
: "未命名".tr, : '未命名'.tr,
AppConstants()
.text_length, // 这里设置最大长度,按你需求改,比如 6~10 字符
),
style: TextStyle( style: TextStyle(
fontFamily: 'Inter', fontFamily: 'Inter',
color: themeController.currentColor.sc3, color: themeController.currentColor.sc3,
@@ -491,3 +508,10 @@ class _MinePageState extends State<NewMinePage> {
); );
} }
} }
String limitText(String? text, int maxLength) {
if (text == null || text.isEmpty) return '';
if (text.characters.length <= maxLength) return text;
return text.characters.take(maxLength).toString() + '...';
}

View File

@@ -85,7 +85,6 @@ class _UpdateUserPageState extends State<EditUserPage> {
left: 0.rpx, left: 0.rpx,
child: returnIconButtomNew(), child: returnIconButtomNew(),
), ),
], ],
), ),
), ),
@@ -165,6 +164,144 @@ class _UpdateUserPageState extends State<EditUserPage> {
), ),
), ),
), ),
// Padding(
// padding: EdgeInsetsDirectional.fromSTEB(
// 30.rpx, 79.rpx, 30.rpx, 0.rpx),
// child: Container(
// width: double.infinity,
// decoration: BoxDecoration(
// border: Border(
// top: BorderSide(
// color: themeController.currentColor.sc4
// .withOpacity(0.5),
// width: AppConstants().border_width,
// ),
// bottom: BorderSide(
// color: themeController.currentColor.sc4
// .withOpacity(0.5),
// width: AppConstants().border_width,
// ),
// ),
// ),
// child: Row(
// mainAxisSize: MainAxisSize.max,
// mainAxisAlignment:
// MainAxisAlignment.spaceBetween,
// children: [
// Expanded(
// child: Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Expanded(
// child: Stack(
// children: [
// TextFormField(
// initialValue: userInfoController
// .model.user!.nick_name,
// onChanged: (value) {
// userInfoController.model.user!
// .tmpNickName = value;
// },
// maxLength:
// AppConstants().text_length,
// maxLines: 1,
// textAlign: TextAlign.center,
// textAlignVertical:
// TextAlignVertical.center,
// buildCounter: (_,
// {int? currentLength,
// bool? isFocused,
// int? maxLength}) =>
// null, // 禁用默认计数器
// decoration: InputDecoration(
// contentPadding:
// EdgeInsets.symmetric(
// vertical: 30.rpx),
// isDense: true,
// hintText: '未命名'.tr,
// hintStyle: TextStyle(
// fontFamily: 'Inter',
// fontSize: 26.rpx,
// color: themeController
// .currentColor.sc4,
// ),
// enabledBorder:
// OutlineInputBorder(
// borderSide: BorderSide(
// color:
// Colors.transparent,
// width: 1.rpx),
// borderRadius:
// BorderRadius.circular(
// 8.rpx),
// ),
// focusedBorder:
// OutlineInputBorder(
// borderSide: BorderSide(
// color:
// Colors.transparent,
// width: 1.rpx),
// borderRadius:
// BorderRadius.circular(
// 8.rpx),
// ),
// errorBorder:
// OutlineInputBorder(
// borderSide: BorderSide(
// width: 1.rpx),
// borderRadius:
// BorderRadius.circular(
// 8.rpx),
// ),
// focusedErrorBorder:
// OutlineInputBorder(
// borderSide: BorderSide(
// width: 1.rpx),
// borderRadius:
// BorderRadius.circular(
// 8.rpx),
// ),
// filled: false,
// ),
// style: TextStyle(
// fontFamily: 'Inter',
// fontSize: 26.rpx,
// color: themeController
// .currentColor.sc3,
// ),
// cursorColor: themeController
// .currentColor.sc3,
// ),
// // 自定义右下角计数器
// Positioned(
// bottom: 4.rpx,
// right: 8.rpx,
// child: Obx(() {
// final text =
// userInfoController
// .model
// .user!
// .tmpNickName ??
// '';
// return Text(
// '${text.length} / ${AppConstants().text_length}',
// style: TextStyle(
// fontSize: 20.rpx,
// color: Colors.grey,
// ),
// );
// }),
// ),
// ],
// )),
// ].divide(SizedBox(width: 27.rpx)),
// ),
// ),
// ],
// ),
// ),
// ),
Padding( Padding(
padding: EdgeInsetsDirectional.fromSTEB( padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 79.rpx, 30.rpx, 0.rpx), 30.rpx, 79.rpx, 30.rpx, 0.rpx),
@@ -194,17 +331,16 @@ class _UpdateUserPageState extends State<EditUserPage> {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
Expanded( Expanded(
child: Stack( child: Center(
children: [ // 让输入框垂直居中对齐
TextFormField( child: TextFormField(
initialValue: userInfoController initialValue: userInfoController
.model.user!.nick_name, .model.user!.nick_name,
onChanged: (value) { onChanged: (value) {
userInfoController.model.user! userInfoController.model.user!
.tmpNickName = value; .tmpNickName = value;
}, },
maxLength: maxLength: null, // 不限制字数
AppConstants().text_length,
maxLines: 1, maxLines: 1,
textAlign: TextAlign.center, textAlign: TextAlign.center,
textAlignVertical: textAlignVertical:
@@ -213,11 +349,12 @@ class _UpdateUserPageState extends State<EditUserPage> {
{int? currentLength, {int? currentLength,
bool? isFocused, bool? isFocused,
int? maxLength}) => int? maxLength}) =>
null, // 禁用默认计数器 null,
decoration: InputDecoration( decoration: InputDecoration(
contentPadding: contentPadding:
EdgeInsets.symmetric( EdgeInsets.symmetric(
vertical: 30.rpx), vertical: 26.rpx,
horizontal: 10.rpx),
isDense: true, isDense: true,
hintText: '未命名'.tr, hintText: '未命名'.tr,
hintStyle: TextStyle( hintStyle: TextStyle(
@@ -266,43 +403,23 @@ class _UpdateUserPageState extends State<EditUserPage> {
), ),
style: TextStyle( style: TextStyle(
fontFamily: 'Inter', fontFamily: 'Inter',
fontSize: 26.rpx, fontSize: 30.rpx,
color: themeController color: themeController
.currentColor.sc3, .currentColor.sc3,
height: 1.0, // 防止偏移
), ),
cursorColor: themeController cursorColor: themeController
.currentColor.sc3, .currentColor.sc3,
), ),
),
// 自定义右下角计数器 ),
Positioned(
bottom: 4.rpx,
right: 8.rpx,
child: Obx(() {
final text =
userInfoController
.model
.user!
.tmpNickName ??
'';
return Text(
'${text.length} / ${AppConstants().text_length}',
style: TextStyle(
fontSize: 20.rpx,
color: Colors.grey,
),
);
}),
),
],
)),
].divide(SizedBox(width: 27.rpx)), ].divide(SizedBox(width: 27.rpx)),
), ),
), ),
], ],
), ),
), ),
), )
], ],
), ),
), ),