|
|
|
@ -33,8 +33,6 @@ class MessageBubble extends GetView<AgentController> { |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
final timeFormat = DateFormat('HH:mm'); |
|
|
|
|
|
|
|
return Padding( |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8), |
|
|
|
child: Row( |
|
|
|
@ -91,7 +89,7 @@ class MessageBubble extends GetView<AgentController> { |
|
|
|
children: [ |
|
|
|
// 时间戳(左对齐或右对齐) |
|
|
|
Text( |
|
|
|
timeFormat.format(timestamp), |
|
|
|
_formatTimestamp(timestamp), |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 10, |
|
|
|
color: Theme.of(context).brightness == Brightness.dark |
|
|
|
@ -105,7 +103,7 @@ class MessageBubble extends GetView<AgentController> { |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.only(left: 8), |
|
|
|
child: Text( |
|
|
|
"generatedByAi".tr,// 由AI生成 |
|
|
|
"generatedByAi".tr, // 由AI生成 |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 8, |
|
|
|
color: Colors.blue[600], |
|
|
|
@ -418,6 +416,77 @@ class MessageBubble extends GetView<AgentController> { |
|
|
|
Widget _buildDot(int milliseconds) { |
|
|
|
return _AnimatedDot(delayMilliseconds: milliseconds); |
|
|
|
} |
|
|
|
|
|
|
|
/// 智能格式化时间戳 |
|
|
|
String _formatTimestamp(DateTime messageTime) { |
|
|
|
final now = DateTime.now(); |
|
|
|
final today = DateTime(now.year, now.month, now.day); |
|
|
|
final yesterday = today.subtract(const Duration(days: 1)); |
|
|
|
final messageDate = |
|
|
|
DateTime(messageTime.year, messageTime.month, messageTime.day); |
|
|
|
|
|
|
|
// 计算时间差 |
|
|
|
final difference = now.difference(messageTime); |
|
|
|
|
|
|
|
// 1分钟内显示"刚刚" |
|
|
|
if (difference.inMinutes < 1) { |
|
|
|
return 'justNow'.tr; // 刚刚 |
|
|
|
} |
|
|
|
|
|
|
|
// 1小时内显示"X分钟前" |
|
|
|
if (difference.inHours < 1) { |
|
|
|
return 'minutesAgo' |
|
|
|
.trParams({'minutes': difference.inMinutes.toString()}); // X分钟前 |
|
|
|
} |
|
|
|
|
|
|
|
// 今天的消息显示时间 |
|
|
|
if (messageDate == today) { |
|
|
|
return DateFormat('HH:mm').format(messageTime); |
|
|
|
} |
|
|
|
|
|
|
|
// 昨天的消息显示"昨天 HH:mm" |
|
|
|
if (messageDate == yesterday) { |
|
|
|
return 'yesterday'.tr + |
|
|
|
' ' + |
|
|
|
DateFormat('HH:mm').format(messageTime); // 昨天 HH:mm |
|
|
|
} |
|
|
|
|
|
|
|
// 本周内的消息显示"星期X HH:mm" |
|
|
|
if (difference.inDays < 7) { |
|
|
|
final weekday = _getWeekdayName(messageTime.weekday); |
|
|
|
return weekday + ' ' + DateFormat('HH:mm').format(messageTime); |
|
|
|
} |
|
|
|
|
|
|
|
// 今年的消息显示"MM-dd HH:mm" |
|
|
|
if (messageTime.year == now.year) { |
|
|
|
return DateFormat('MM-dd HH:mm').format(messageTime); |
|
|
|
} |
|
|
|
|
|
|
|
// 其他情况显示完整日期"yyyy-MM-dd HH:mm" |
|
|
|
return DateFormat('yyyy-MM-dd HH:mm').format(messageTime); |
|
|
|
} |
|
|
|
|
|
|
|
/// 获取星期名称 |
|
|
|
String _getWeekdayName(int weekday) { |
|
|
|
switch (weekday) { |
|
|
|
case 1: |
|
|
|
return 'monday'.tr; // 星期一 |
|
|
|
case 2: |
|
|
|
return 'tuesday'.tr; // 星期二 |
|
|
|
case 3: |
|
|
|
return 'wednesday'.tr; // 星期三 |
|
|
|
case 4: |
|
|
|
return 'thursday'.tr; // 星期四 |
|
|
|
case 5: |
|
|
|
return 'friday'.tr; // 星期五 |
|
|
|
case 6: |
|
|
|
return 'saturday'.tr; // 星期六 |
|
|
|
case 7: |
|
|
|
return 'sunday'.tr; // 星期日 |
|
|
|
default: |
|
|
|
return ''; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// 动画点组件 |
|
|
|
|