import 'package:flutter/material.dart'; /// The small, non-selectable metadata line for a recorded chat message time. /// The visible value includes a local date so messages from different days are /// not ambiguous; the tooltip and semantics expose the full localized value. class ChatMessageTimestamp extends StatelessWidget { const ChatMessageTimestamp({super.key, required this.createdAt}); final int? createdAt; @override Widget build(BuildContext context) { final instant = createdAt == null ? null : DateTime.fromMillisecondsSinceEpoch( createdAt!, isUtc: true, ).toLocal(); if (instant == null) return const SizedBox.shrink(); final material = MaterialLocalizations.of(context); final time = material.formatTimeOfDay( TimeOfDay.fromDateTime(instant), alwaysUse24HourFormat: true, ); final date = '${instant.day} ${material.formatMonthYear(instant)}'; final full = '$date, $time'; final style = (Theme.of(context).textTheme.bodySmall ?? const TextStyle()) .copyWith( color: Theme.of(context).colorScheme.onSurfaceVariant, fontSize: 12, ); final label = 'Sent $full'; final text = Text('$date ยท $time', style: style); return SelectionContainer.disabled( child: Tooltip( message: full, child: Semantics( container: true, label: label, excludeSemantics: true, child: text, ), ), ); } }