import 'package:flutter/material.dart'; /// The local date as the transcript's day divider names it: `25 November 2026`. String chatDayLabel(BuildContext context, DateTime day) => '${day.day} ${MaterialLocalizations.of(context).formatMonthYear(day)}'; /// The small, non-selectable time of a recorded chat message: `10:16`. The /// date is named once per day by [ChatDayDivider]; the tooltip and semantics /// still carry the full localized date and time. 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 full = '${chatDayLabel(context, instant)}, $time'; final style = chatMetaTextStyle(context); return SelectionContainer.disabled( child: Tooltip( message: full, child: Semantics( container: true, label: 'Sent $full', excludeSemantics: true, child: Text(time, style: style), ), ), ); } } /// The muted small text of transcript metadata (times, the answering model). TextStyle? chatMetaTextStyle(BuildContext context) => Theme.of(context) .textTheme .bodySmall ?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant); /// A transcript row with the [ChatDayDivider] for [day] above it when the row /// starts a calendar day. The row keeps its element whether or not a divider /// joins or leaves above it (an older page arriving moves the day's start). class ChatDayDivided extends StatelessWidget { const ChatDayDivided({ super.key, required this.day, required this.child, this.inset = 0, }); final DateTime? day; /// Leading space before the divider, so it keeps to the reading column. final double inset; final Widget child; @override Widget build(BuildContext context) { final day = this.day; return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ if (day != null) Padding( key: const ValueKey('chat-day-divider'), padding: EdgeInsetsDirectional.only(start: inset), child: ChatDayDivider(day: day), ), KeyedSubtree(key: const ValueKey('chat-day-row'), child: child), ], ); } } /// A quiet centred date between two thin rules, above the first message of /// each calendar day in the transcript. class ChatDayDivider extends StatelessWidget { const ChatDayDivider({super.key, required this.day}); final DateTime day; @override Widget build(BuildContext context) { final label = chatDayLabel(context, day); return SelectionContainer.disabled( child: Semantics( container: true, header: true, label: label, excludeSemantics: true, child: Padding( padding: const EdgeInsets.only(top: 12, bottom: 4), child: Row( children: [ const Expanded(child: Divider()), Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: Text(label, style: chatMetaTextStyle(context)), ), const Expanded(child: Divider()), ], ), ), ), ); } }