toSmartChatTime property

String get toSmartChatTime

Returns smart chat timestamp based on when message was sent

Implementation

String get toSmartChatTime {
  final now = DateTime.now();
  final localTime = toLocal();
  final difference = now.difference(localTime);

  // Today: show time only
  if (difference.inDays == 0) {
    return to12HourFormat;
  }

  // Yesterday
  if (difference.inDays == 1) {
    return 'Yesterday';
  }

  // This week: show day name
  if (difference.inDays < 7) {
    final days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
    return days[localTime.weekday - 1];
  }

  // This year: show month and day
  if (localTime.year == now.year) {
    final months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    return '${months[localTime.month - 1]} ${localTime.day}';
  }

  // Different year: show full date
  return toDateAsString;
}