diff --git a/lib/pages/main_bottom/component/MessageWidgetWidget.dart b/lib/pages/main_bottom/component/MessageWidgetWidget.dart index eb3d9bf..0cc2bda 100644 --- a/lib/pages/main_bottom/component/MessageWidgetWidget.dart +++ b/lib/pages/main_bottom/component/MessageWidgetWidget.dart @@ -167,13 +167,14 @@ class _MessageWidgetWidgetState extends State { child: Align( alignment: AlignmentDirectional(-1, 0), child: Text( + label.tr, overflow: TextOverflow.ellipsis, maxLines: 1, - label.tr, style: TextStyle( fontFamily: 'Inter', fontSize: 26.rpx, letterSpacing: 0.0, + height: 1, color: themeController.currentColor.sc4, ), ), @@ -189,13 +190,14 @@ class _MessageWidgetWidgetState extends State { child: Align( alignment: AlignmentDirectional(-1, 0), child: Text( + "${value}", overflow: TextOverflow.ellipsis, maxLines: 1, - "${value}", style: TextStyle( fontFamily: 'Inter', fontSize: 26.rpx, letterSpacing: 0.0, + height: 1, color: themeController.currentColor.sc3, ), ), diff --git a/lib/pages/mh_page/bluetooth.dart b/lib/pages/mh_page/bluetooth.dart index f301cea..3c4cbe9 100644 --- a/lib/pages/mh_page/bluetooth.dart +++ b/lib/pages/mh_page/bluetooth.dart @@ -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 { 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 { : '删除'.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 { ), ); } + + 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; +// } diff --git a/lib/pages/mh_page/edit_bed.dart b/lib/pages/mh_page/edit_bed.dart index af1323b..4a56f61 100644 --- a/lib/pages/mh_page/edit_bed.dart +++ b/lib/pages/mh_page/edit_bed.dart @@ -210,12 +210,6 @@ class _EditBedPageState extends State { textAlign: TextAlign.center, textAlignVertical: TextAlignVertical.center, - maxLength: AppConstants().text_length, - buildCounter: (_, - {int? currentLength, - bool? isFocused, - int? maxLength}) => - null, decoration: InputDecoration( hintText: "请输入设备的名称".tr, contentPadding: @@ -262,101 +256,16 @@ class _EditBedPageState extends State { letterSpacing: 0, ), cursorColor: Colors.white, - ), - - // 自定义右下角计数器 - Positioned( - bottom: 2.rpx, - right: 10.rpx, - child: Text( - '${_nameController.text.characters.length} / ${AppConstants().text_length}', - style: TextStyle( - fontSize: 24.rpx, - color: const Color(0xFF929699), - fontFamily: 'Readex Pro', - ), - ), + // ✅ 允许横向滚动防止溢出: + keyboardType: TextInputType.text, + maxLines: 1, + scrollPadding: EdgeInsets.zero, + enableInteractiveSelection: true, + expands: false, ), ], ), ), - - // 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, - // ), - // ), - // ) ) ], ), diff --git a/lib/pages/mh_page/new_mine_page.dart b/lib/pages/mh_page/new_mine_page.dart index 230dc05..e061026 100644 --- a/lib/pages/mh_page/new_mine_page.dart +++ b/lib/pages/mh_page/new_mine_page.dart @@ -117,7 +117,7 @@ class _MinePageState extends State { child: Row( children: [ Obx(() { - userInfoController.model.login!; + userInfoController.model.login!; return Container( width: 120.rpx, height: 120.rpx, @@ -151,12 +151,29 @@ class _MinePageState extends State { children: [ Row( 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( - login == 1 - ? (userInfoController - .model.user!.nick_name ?? - '未命名'.tr) - : "未命名".tr, + limitText( + login == 1 + ? userInfoController + .model.user?.nick_name + : '未命名'.tr, + AppConstants() + .text_length, // 这里设置最大长度,按你需求改,比如 6~10 字符 + ), style: TextStyle( fontFamily: 'Inter', color: themeController.currentColor.sc3, @@ -491,3 +508,10 @@ class _MinePageState extends State { ); } } + +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() + '...'; +} diff --git a/lib/pages/mh_page/user/page/edit_userinfo_page.dart b/lib/pages/mh_page/user/page/edit_userinfo_page.dart index 8c307e0..357207c 100644 --- a/lib/pages/mh_page/user/page/edit_userinfo_page.dart +++ b/lib/pages/mh_page/user/page/edit_userinfo_page.dart @@ -85,7 +85,6 @@ class _UpdateUserPageState extends State { left: 0.rpx, child: returnIconButtomNew(), ), - ], ), ), @@ -165,6 +164,144 @@ class _UpdateUserPageState extends State { ), ), ), + // 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: EdgeInsetsDirectional.fromSTEB( 30.rpx, 79.rpx, 30.rpx, 0.rpx), @@ -194,17 +331,16 @@ class _UpdateUserPageState extends State { mainAxisSize: MainAxisSize.max, children: [ Expanded( - child: Stack( - children: [ - TextFormField( + child: Center( + // 让输入框垂直居中对齐 + child: TextFormField( initialValue: userInfoController .model.user!.nick_name, onChanged: (value) { userInfoController.model.user! .tmpNickName = value; }, - maxLength: - AppConstants().text_length, + maxLength: null, // 不限制字数 maxLines: 1, textAlign: TextAlign.center, textAlignVertical: @@ -213,11 +349,12 @@ class _UpdateUserPageState extends State { {int? currentLength, bool? isFocused, int? maxLength}) => - null, // 禁用默认计数器 + null, decoration: InputDecoration( contentPadding: EdgeInsets.symmetric( - vertical: 30.rpx), + vertical: 26.rpx, + horizontal: 10.rpx), isDense: true, hintText: '未命名'.tr, hintStyle: TextStyle( @@ -266,43 +403,23 @@ class _UpdateUserPageState extends State { ), style: TextStyle( fontFamily: 'Inter', - fontSize: 26.rpx, + fontSize: 30.rpx, color: themeController .currentColor.sc3, + height: 1.0, // 防止偏移 ), 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)), ), ), ], ), ), - ), + ) ], ), ),