import 'package:flutter/material.dart'; /// The title line of a chat session row: the session's name, with its relative /// recency at the trailing edge. Shared by the Material and Cupertino rows so /// both hosts arrange the same facts the same way. /// /// The recency takes at most 45% of the text column and ellipsises there, so a /// long title keeps the larger share and a short row never overflows. The /// recency is supplementary: at very large text scales it is the part that /// gives way, while the session's name and state word stay whole. class ChatSessionRowTitle extends StatelessWidget { const ChatSessionRowTitle({ super.key, required this.title, required this.time, required this.timeStyle, }); final String title; final String time; final TextStyle timeStyle; @override Widget build(BuildContext context) { return LayoutBuilder( builder: (context, constraints) => Row( children: [ Expanded( child: Text(title, maxLines: 1, overflow: TextOverflow.ellipsis), ), if (time.isNotEmpty) ...[ const SizedBox(width: 8), ConstrainedBox( constraints: BoxConstraints( maxWidth: constraints.maxWidth * 0.45, ), child: Text( time, maxLines: 1, overflow: TextOverflow.ellipsis, style: timeStyle, ), ), ], ], ), ); } } /// The muted second line of a chat session row: the recorded directory and /// model, with the unread/closed word at the trailing edge. /// /// The directory/model is the part that ellipsises; the state word is the row's /// only unread marker, so it keeps its intrinsic width and the metadata shrinks /// first. If even the whole text column cannot hold the word at the current /// text scale it is scaled down rather than clipped, so `New`/`Closed` is never /// replaced by an ellipsis. class ChatSessionRowMeta extends StatelessWidget { const ChatSessionRowMeta({ super.key, required this.meta, required this.status, required this.metaStyle, required this.statusStyle, }); final String meta; final String? status; final TextStyle metaStyle; final TextStyle statusStyle; /// The trailing word's intrinsic width is measured against the full text /// column, minus this gap, so the row can never overflow the line. static const _statusGap = 8.0; @override Widget build(BuildContext context) { return LayoutBuilder( builder: (context, constraints) => Row( children: [ Expanded( child: Text( meta, maxLines: 1, overflow: TextOverflow.ellipsis, style: metaStyle, ), ), if (status != null) ConstrainedBox( constraints: BoxConstraints(maxWidth: constraints.maxWidth), child: Padding( padding: const EdgeInsetsDirectional.only(start: _statusGap), child: FittedBox( fit: BoxFit.scaleDown, alignment: AlignmentDirectional.centerEnd, child: Text(status!, maxLines: 1, style: statusStyle), ), ), ), ], ), ); } }