fix(app): chat turns are content-sized bubbles without role labels, as the web

This commit is contained in:
2026-10-23 15:43:07 +01:00
parent 702bf8559d
commit c46a46ee14
3 changed files with 51 additions and 42 deletions
@@ -24,21 +24,17 @@ class ChatMessageView extends StatelessWidget {
final role = user ? 'User' : 'Assistant';
final cupertino = _isCupertino(context);
final content = user ? _userParts(context) : _agentParts(context);
// No visible role label, as on the web: side and colour say who spoke and
// the row's semantics label names the role. The bubble shrinks to its
// content (a disclosure still takes the full measure).
final body = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// The row's semantics label already says the role; announcing the
// visible label again would read it twice.
ExcludeSemantics(
child: Text(role, style: _roleStyle(context, cupertino)),
),
...content,
],
crossAxisAlignment: CrossAxisAlignment.start,
children: content,
);
// The web draws the operator's turn right-aligned in an accent-tinted bubble
// and the agent's left-aligned on the neutral surface, both capped to a
// readable measure. The role label stays outside the bubble.
// readable measure.
final contentBody = cupertino
? DefaultTextStyle.merge(
style: CupertinoTheme.of(context).textTheme.textStyle,
@@ -68,20 +64,32 @@ class ChatMessageView extends StatelessWidget {
label: '$role message',
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Align(
alignment: user
? AlignmentDirectional.centerEnd
: AlignmentDirectional.centerStart,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560),
child: bubble,
child: LayoutBuilder(
builder: (context, constraints) => Align(
alignment: user
? AlignmentDirectional.centerEnd
: AlignmentDirectional.centerStart,
child: ConstrainedBox(
// The operator's turn leaves a margin on a phone, so the two
// sides read as a conversation.
constraints: BoxConstraints(
maxWidth: user
? (constraints.maxWidth * 0.85).clamp(0, 560).toDouble()
: 560,
),
child: bubble,
),
),
),
),
);
}
Color _bubbleColor(BuildContext context, bool cupertino, {required bool user}) {
Color _bubbleColor(
BuildContext context,
bool cupertino, {
required bool user,
}) {
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
@@ -103,9 +111,7 @@ class ChatMessageView extends StatelessWidget {
? CupertinoColors.separator.resolveFrom(context)
: Theme.of(context).colorScheme.outlineVariant;
return RoundedRectangleBorder(
side: BorderSide(
color: user ? accent.withValues(alpha: 0.4) : border,
),
side: BorderSide(color: user ? accent.withValues(alpha: 0.4) : border),
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(12),
topRight: const Radius.circular(12),
@@ -148,12 +154,6 @@ class ChatMessageView extends StatelessWidget {
);
}
TextStyle? _roleStyle(BuildContext context, bool cupertino) =>
(cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.labelLarge)
?.copyWith(color: _secondaryColor(context, cupertino));
Color _secondaryColor(BuildContext context, bool cupertino) => cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;