Browse Source

refactor: 优化多个视图的布局和文本显示

- 修复登录控制器中的缩进问题并更新验证码提示文本
- 重构首页断开连接信息的布局,改进多行文本显示
- 优化探索视图的文本布局,支持多行显示和更好的对齐
- 改进设置视图的更新按钮布局和文本显示
- 重构导航卡片布局,优化图标对齐和文本显示
weicu
lxm 1 year ago
parent
commit
c976c97e18
  1. 324
      lib/modules/agent/views/navigation_card.dart
  2. 57
      lib/modules/explore/views/explore_view.dart
  3. 50
      lib/modules/home/views/home_view.dart
  4. 8
      lib/modules/login/controllers/login_controller.dart
  5. 94
      lib/modules/settings/views/settings_view.dart

324
lib/modules/agent/views/navigation_card.dart

@ -221,89 +221,108 @@ Widget navigationCard(
// 底部:目的地信息和操作按钮 // 底部:目的地信息和操作按钮
Container( Container(
padding: EdgeInsets.fromLTRB(20.w, 8.h, 20.w, 16.h), padding: EdgeInsets.fromLTRB(20.w, 8.h, 20.w, 16.h),
child: Stack( child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// 目的地和距离时间信息 // 第一层:起点 → 目的地信息(独占整个宽度)
Padding( Row(
padding: EdgeInsets.only(right: 70.w), // 为右下角按钮留出空间 crossAxisAlignment: CrossAxisAlignment.center, // 确保垂直居中对齐
child: Column( children: [
crossAxisAlignment: CrossAxisAlignment.start, // 起点图标 - 统一图标容器宽度,确保对齐
children: [ SizedBox(
// 路径显示:当前位置 → 目的地 width: 16.sp, // 固定图标容器宽度
Row( child: Icon(
children: [ Icons.my_location,
// 起点图标 size: 15.sp, // 统一图标大小
Icon( color: Theme.of(context).primaryColor,
Icons.my_location, ),
size: 16.sp, ),
color: Theme.of(context).primaryColor, SizedBox(width: 6.w), // 统一间距
), // 当前位置文本
// SizedBox(width: 6.w), Text(
// // 当前位置文本 'currentLocation'.tr, // 当前位置
// Text( style: TextStyle(
// 'currentLocation'.tr, // 当前位置 fontSize: 14.sp,
// style: TextStyle( fontWeight: FontWeight.w500,
// fontSize: 14.sp, color: isDarkMode
// fontWeight: FontWeight.w500, ? Colors.white70
// color: isDarkMode : Colors.black54,
// ? Colors.white70 height: 1.3, // 设置行高,提升多行文本可读性
// : Colors.black54,
// ),
// ),
SizedBox(width: 8.w),
// 箭头图标
Icon(
Icons.arrow_forward,
size: 16.sp,
color:
isDarkMode ? Colors.white54 : Colors.black45,
),
SizedBox(width: 8.w),
// 目的地图标
Icon(
Icons.location_on,
size: 16.sp,
color: Colors.red,
),
SizedBox(width: 6.w),
// 目的地名称
Expanded(
child: Text(
destination,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: isDarkMode
? Colors.white
: Colors.black87,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
), ),
SizedBox(height: 4.h), softWrap: true, // 启用软换行
// 距离和时间信息 overflow: TextOverflow.visible, // 确保文本完全显示
Column( ),
SizedBox(width: 8.w),
// 箭头图标
Icon(
Icons.arrow_forward,
size: 15.sp, // 统一图标大小
color: isDarkMode ? Colors.white54 : Colors.black45,
),
SizedBox(width: 8.w),
// 目的地图标
Icon(
Icons.location_on,
size: 15.sp, // 统一图标大小
color: Colors.red,
),
SizedBox(width: 6.w), // 统一间距
// 目的地名称 - 使用Expanded确保自动换行
Expanded(
child: Text(
destination,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: isDarkMode
? Colors.white
: Colors.black87,
height: 1.2, // 设置行高,提升多行文本可读性
),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
),
),
],
),
SizedBox(height: 4.h), // 第一层和第二层之间的间距
// 第二层:距离时间信息(左侧)+ 导航按钮(右侧)
Row(
crossAxisAlignment: CrossAxisAlignment.end, // 底部对齐
children: [
// 左侧:距离和时间信息
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// 距离信息 // 距离信息
Row( Row(
crossAxisAlignment: CrossAxisAlignment.center, // 确保垂直居中对齐
children: [ children: [
Icon( // 距离图标 - 统一图标容器宽度,确保与第一层对齐
Icons.straighten, SizedBox(
size: 14.sp, width: 16.sp, // 与第一层图标容器宽度一致
color: Theme.of(context).primaryColor, child: Icon(
), Icons.straighten,
SizedBox(width: 4.w), size: 15.sp, // 统一图标大小
Text(
formatDistance(
modes[currentIndex]["distance"]),
style: TextStyle(
fontSize: 14.sp,
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w500, ),
),
SizedBox(width: 6.w), // 与第一层间距一致
Flexible(
child: Text(
formatDistance(
modes[currentIndex]["distance"]),
style: TextStyle(
fontSize: 14.sp,
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w500,
height: 1.3, // 设置行高,提升多行文本可读性
),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
), ),
], ],
@ -311,95 +330,106 @@ Widget navigationCard(
SizedBox(height: 4.h), SizedBox(height: 4.h),
// 时间信息 // 时间信息
Row( Row(
crossAxisAlignment: CrossAxisAlignment.center, // 确保垂直居中对齐
children: [ children: [
Icon( // 时间图标 - 统一图标容器宽度,确保与第一层对齐
Icons.access_time, SizedBox(
size: 14.sp, width: 16.sp, // 与第一层图标容器宽度一致
color: Theme.of(context).primaryColor, child: Icon(
Icons.access_time,
size: 15.sp, // 统一图标大小
color: Theme.of(context).primaryColor,
),
), ),
SizedBox(width: 4.w), SizedBox(width: 6.w), // 与第一层间距一致
Text( Flexible(
'${'approximate'.tr}${formatDuration(modes[currentIndex]["duration"])}', // 约 child: Text(
'${'approximate'.tr}${formatDuration(modes[currentIndex]["duration"])}', // 约
style: TextStyle(
fontSize: 14.sp,
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w500,
height: 1.3, // 设置行高,提升多行文本可读性
),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
),
),
],
),
// 导航状态信息
if (navigation != null) ...[
SizedBox(height: 6.h),
Container(
padding: EdgeInsets.symmetric(
horizontal: 8.w, vertical: 4.h),
decoration: BoxDecoration(
color: Theme.of(context)
.primaryColor
.withOpacity(0.1),
borderRadius: BorderRadius.circular(6.r),
),
child: Text(
"${navigation["distanceText"]}${'enterRoad'.tr}${navigation["nextRoad"]}", // 进入
style: TextStyle( style: TextStyle(
fontSize: 14.sp, fontSize: 12.sp,
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
height: 1.3, // 设置行高,提升多行文本可读性
), ),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
],
),
],
),
// 导航状态信息
if (navigation != null) ...[
SizedBox(height: 6.h),
Container(
padding: EdgeInsets.symmetric(
horizontal: 8.w, vertical: 4.h),
decoration: BoxDecoration(
color: Theme.of(context)
.primaryColor
.withOpacity(0.1),
borderRadius: BorderRadius.circular(6.r),
),
child: Text(
"${navigation["distanceText"]}${'enterRoad'.tr}${navigation["nextRoad"]}", // 进入
style: TextStyle(
fontSize: 12.sp,
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w500,
), ),
), ],
),
],
],
),
),
// 开始导航按钮 - 绝对定位到右下角
Positioned(
right: 0,
bottom: 0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).primaryColor,
Theme.of(context).primaryColor.withOpacity(0.8),
], ],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
), ),
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color:
Theme.of(context).primaryColor.withOpacity(0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
), ),
child: Material(
color: Colors.transparent, SizedBox(width: 16.w), // 左右内容之间的间距
child: InkWell(
// 右侧:开始导航按钮
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).primaryColor,
Theme.of(context).primaryColor.withOpacity(0.8),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
onTap: () { boxShadow: [
controller.openNavigation(start, end, ""); BoxShadow(
}, color: Theme.of(context).primaryColor.withOpacity(0.3),
child: Container( blurRadius: 8,
padding: EdgeInsets.symmetric( offset: const Offset(0, 2),
horizontal: 16.w,
vertical: 12.h,
), ),
child: Icon( ],
Icons.navigation, ),
color: Colors.white, child: Material(
size: 20.sp, color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(12.r),
onTap: () {
controller.openNavigation(start, end, "");
},
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 16.w,
vertical: 12.h,
),
child: Icon(
Icons.navigation,
color: Colors.white,
size: 20.sp,
),
), ),
), ),
), ),
), ),
), ],
), ),
], ],
), ),

57
lib/modules/explore/views/explore_view.dart

@ -208,29 +208,42 @@ class ExploreView extends GetView<ExploreController> {
), ),
// 文本内容 // 文本内容
Padding( Positioned(
padding: EdgeInsets.all(24.w), bottom: 0,
child: Column( left: 0,
mainAxisAlignment: MainAxisAlignment.end, right: 0,
crossAxisAlignment: CrossAxisAlignment.start, child: Padding(
children: [ padding: EdgeInsets.all(24.w),
Text( child: Column(
title, mainAxisSize: MainAxisSize.min, // 使用最小尺寸,避免占用过多空间
style: TextStyle( crossAxisAlignment: CrossAxisAlignment.start,
fontSize: 22.sp, children: [
fontWeight: FontWeight.bold, // 标题文本 - 支持多行显示
color: Colors.white, Text(
title,
style: TextStyle(
fontSize: 22.sp,
fontWeight: FontWeight.bold,
color: Colors.white,
height: 1.2, // 设置行高,提升多行文本可读性
),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
), SizedBox(height: 6.h), // 稍微增加间距,适应多行布局
SizedBox(height: 4.h), // 描述文本 - 支持多行显示
Text( Text(
description, description,
style: TextStyle( style: TextStyle(
fontSize: 14.sp, fontSize: 14.sp,
color: Colors.white.withOpacity(0.8), color: Colors.white.withOpacity(0.8),
height: 1.3, // 设置行高,提升多行文本可读性
),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
), ],
], ),
), ),
), ),
], ],
@ -341,7 +354,7 @@ class ExploreView extends GetView<ExploreController> {
fontSize: 12.sp, fontSize: 12.sp,
color: isDarkMode ? Colors.grey[400] : Colors.grey[600], color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
), ),
maxLines: 1, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
], ],

50
lib/modules/home/views/home_view.dart

@ -519,7 +519,6 @@ class HomeView extends GetView<HomeController> {
Widget _buildDisconnectedInfo(bool isDarkMode) { Widget _buildDisconnectedInfo(bool isDarkMode) {
return Container( return Container(
padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 12.w), padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 12.w),
alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
color: isDarkMode ? Colors.grey[900] : Colors.grey[100], color: isDarkMode ? Colors.grey[900] : Colors.grey[100],
borderRadius: BorderRadius.circular(10.r), borderRadius: BorderRadius.circular(10.r),
@ -528,26 +527,37 @@ class HomeView extends GetView<HomeController> {
width: 1, width: 1,
), ),
), ),
child: Row( child: IntrinsicHeight(
mainAxisAlignment: MainAxisAlignment.center, child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.center, // 整体居中对齐
Icon( crossAxisAlignment: CrossAxisAlignment.start, // 顶部对齐,适应多行文本
Icons.bluetooth_disabled, children: [
size: 14.sp, // 图标容器,与文本第一行基线对齐
color: isDarkMode ? Colors.grey[400] : Colors.grey[700], Padding(
), padding: EdgeInsets.only(top: 1.h), // 微调图标位置,与文本第一行基线对齐
SizedBox(height: 12.h), child: Icon(
Text( Icons.bluetooth_disabled,
'disconnectedDevice'.tr, // 未连接设备,点击下方按钮连接 size: 14.sp,
style: TextStyle( color: isDarkMode ? Colors.grey[400] : Colors.grey[700],
fontSize: 12.sp, ),
color: isDarkMode ? Colors.grey[400] : Colors.grey[700],
// height: 1.4,
// fontWeight: FontWeight.w500,
), ),
//textAlign: TextAlign.center, SizedBox(width: 6.w), // 图标和文本间距
), // 文本容器,使用Flexible确保自动换行且保持居中效果
], Flexible(
child: Text(
'disconnectedDevice'.tr, // 未连接设备,点击下方按钮连接
style: TextStyle(
fontSize: 12.sp,
color: isDarkMode ? Colors.grey[400] : Colors.grey[700],
height: 1.4, // 启用行高,提升多行文本可读性
),
textAlign: TextAlign.center, // 文本居中对齐
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
),
),
],
),
), ),
); );
} }

8
lib/modules/login/controllers/login_controller.dart

@ -211,9 +211,9 @@ class LoginController extends GetxController {
if (!_hasAcceptedPrivacy.value) { if (!_hasAcceptedPrivacy.value) {
_showPrivacyDialog(); _showPrivacyDialog();
} else { } else {
_initDeviceInfo(); _initDeviceInfo();
_initAppInfo(); // 新增:初始化APP信息 _initAppInfo(); // 新增:初始化APP信息
_checkGuestLoginConfig(); // 检查游客登录配置 _checkGuestLoginConfig(); // 检查游客登录配置
} }
}); });
} }
@ -731,7 +731,7 @@ class LoginController extends GetxController {
if (!isVerificationCodeComplete()) { if (!isVerificationCodeComplete()) {
Get.snackbar( Get.snackbar(
'tip'.tr, 'tip'.tr,
'pleaseEnterVerificationCode'.tr, 'pleaseEnterCompleteCode'.tr,
snackPosition: SnackPosition.TOP, snackPosition: SnackPosition.TOP,
backgroundColor: Colors.red.withOpacity(0.1), backgroundColor: Colors.red.withOpacity(0.1),
colorText: Colors.red, colorText: Colors.red,

94
lib/modules/settings/views/settings_view.dart

@ -715,8 +715,8 @@ class SettingsView extends GetView<SettingsController> {
? ImageFilter.blur(sigmaX: 5, sigmaY: 5) ? ImageFilter.blur(sigmaX: 5, sigmaY: 5)
: ImageFilter.blur(sigmaX: 0, sigmaY: 0), : ImageFilter.blur(sigmaX: 0, sigmaY: 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
// 左侧应用信息区域 - 使用固定宽度
Row( Row(
children: [ children: [
Container( Container(
@ -770,36 +770,46 @@ class SettingsView extends GetView<SettingsController> {
), ),
], ],
), ),
InkWell(
onTap: () { // 间距
// 调用检查更新方法 SizedBox(width: 16.w),
controller.checkForUpdate();
}, // 右侧检查更新按钮 - 使用Expanded确保充分利用剩余空间
child: Container( Expanded(
constraints: BoxConstraints( child: InkWell(
minWidth: 100.w, onTap: () {
maxWidth: 180.w, // 调用检查更新方法
), controller.checkForUpdate();
padding: EdgeInsets.symmetric( },
horizontal: 16.w, child: Container(
vertical: 8.h, constraints: BoxConstraints(
), minHeight: 36.h, // 设置最小高度而不是宽度约束
decoration: BoxDecoration( ),
color: isDarkMode padding: EdgeInsets.symmetric(
? Colors.blue[900]!.withOpacity(0.3) horizontal: 12.w,
: Colors.blue[100], vertical: 8.h,
borderRadius: BorderRadius.circular(16.r), ),
), decoration: BoxDecoration(
child: Text( color: isDarkMode
'checkUpdates'.tr, // 检查更新 ? Colors.blue[900]!.withOpacity(0.3)
style: TextStyle( : Colors.blue[100],
fontSize: 12.sp, borderRadius: BorderRadius.circular(16.r),
color: ),
isDarkMode ? Colors.blue[300] : Colors.blue[600], child: Center(
child: FittedBox(
fit: BoxFit.scaleDown, // 如果文本过长,自动缩小字体
child: Text(
'checkUpdates'.tr, // 检查更新
style: TextStyle(
fontSize: 12.sp,
color: isDarkMode ? Colors.blue[300] : Colors.blue[600],
height: 1.2, // 稍微减少行高,适应FittedBox
),
textAlign: TextAlign.center,
maxLines: 2, // 最多显示2行,配合FittedBox使用
),
),
), ),
overflow: TextOverflow.ellipsis, // 添加省略号
maxLines: 1, // 限制为单行
textAlign: TextAlign.center, // 保持居中
), ),
), ),
), ),
@ -905,8 +915,10 @@ class SettingsView extends GetView<SettingsController> {
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: isDarkMode ? Colors.white : Colors.black87, color: isDarkMode ? Colors.white : Colors.black87,
height: 1.2, // 设置行高,提升多行文本可读性
), ),
overflow: TextOverflow.ellipsis, softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
if (subtitle != null) SizedBox(height: 2.h), if (subtitle != null) SizedBox(height: 2.h),
if (subtitle != null) if (subtitle != null)
@ -915,8 +927,10 @@ class SettingsView extends GetView<SettingsController> {
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
color: isDarkMode ? Colors.white70 : Colors.black54, color: isDarkMode ? Colors.white70 : Colors.black54,
height: 1.3, // 设置行高,提升多行文本可读性
), ),
overflow: TextOverflow.ellipsis, softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
], ],
), ),
@ -980,8 +994,10 @@ class SettingsView extends GetView<SettingsController> {
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: isDarkMode ? Colors.white : Colors.black87, color: isDarkMode ? Colors.white : Colors.black87,
height: 1.2, // 设置行高,提升多行文本可读性
), ),
overflow: TextOverflow.ellipsis, softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
if (subtitle != null) SizedBox(height: 2.h), if (subtitle != null) SizedBox(height: 2.h),
if (subtitle != null) if (subtitle != null)
@ -991,8 +1007,10 @@ class SettingsView extends GetView<SettingsController> {
fontSize: 12.sp, fontSize: 12.sp,
color: color:
isDarkMode ? Colors.white70 : Colors.black54, isDarkMode ? Colors.white70 : Colors.black54,
height: 1.3, // 设置行高,提升多行文本可读性
), ),
overflow: TextOverflow.ellipsis, softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
], ],
), ),
@ -1085,8 +1103,10 @@ class SettingsView extends GetView<SettingsController> {
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: titleColor ?? color: titleColor ??
(isDarkMode ? Colors.white : Colors.black87), (isDarkMode ? Colors.white : Colors.black87),
height: 1.2, // 设置行高,提升多行文本可读性
), ),
overflow: TextOverflow.ellipsis, softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
if (subtitle != null) SizedBox(height: 2.h), if (subtitle != null) SizedBox(height: 2.h),
if (subtitle != null) if (subtitle != null)
@ -1098,8 +1118,10 @@ class SettingsView extends GetView<SettingsController> {
(isDarkMode (isDarkMode
? Colors.white70 ? Colors.white70
: Colors.black54), : Colors.black54),
height: 1.3, // 设置行高,提升多行文本可读性
), ),
overflow: TextOverflow.ellipsis, softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
), ),
], ],
), ),

Loading…
Cancel
Save