88 lines
2.7 KiB
Dart
88 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// A chat session row line with the unread/closed word at its trailing edge:
|
|
/// the row's title line, as on the web.
|
|
///
|
|
/// 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: status == 'New'
|
|
? _UnreadBadge(style: statusStyle)
|
|
: Text(status!, maxLines: 1, style: statusStyle),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A chat with messages not yet seen: the word in a filled pill.
|
|
class _UnreadBadge extends StatelessWidget {
|
|
const _UnreadBadge({required this.style});
|
|
|
|
final TextStyle style;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final color = style.color ?? const Color(0xFF0A84FF);
|
|
return DecoratedBox(
|
|
key: const Key('chat-row-unread'),
|
|
decoration: ShapeDecoration(color: color, shape: const StadiumBorder()),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
|
|
child: Text(
|
|
'New',
|
|
maxLines: 1,
|
|
style: style.copyWith(
|
|
color: const Color(0xFFFFFFFF),
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|