From c46a46ee14ad4f7c756fadd0934935767647a171 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 15:43:07 +0100 Subject: [PATCH] fix(app): chat turns are content-sized bubbles without role labels, as the web --- .../chat/ui/transcript/chat_message_view.dart | 54 +++++++++---------- .../ui/transcript/chat_message_view_test.dart | 31 ++++++++--- .../chat_unknown_user_part_test.dart | 8 +-- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/app/lib/features/chat/ui/transcript/chat_message_view.dart b/app/lib/features/chat/ui/transcript/chat_message_view.dart index 7dabb9a8..a6114062 100644 --- a/app/lib/features/chat/ui/transcript/chat_message_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_message_view.dart @@ -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; diff --git a/app/test/features/chat/ui/transcript/chat_message_view_test.dart b/app/test/features/chat/ui/transcript/chat_message_view_test.dart index d644229d..a74c2165 100644 --- a/app/test/features/chat/ui/transcript/chat_message_view_test.dart +++ b/app/test/features/chat/ui/transcript/chat_message_view_test.dart @@ -66,16 +66,15 @@ void main() { await tester.pumpWidget(_host(_userRow(), scale: 2)); await tester.pumpAndSettle(); - expect(find.text('User'), findsOneWidget); + // Side and colour say who spoke; the role is a semantics label only. + expect(find.text('User'), findsNothing); + expect(find.bySemanticsLabel('User message'), findsOneWidget); expect(find.text('Ada phone'), findsOneWidget); expect(find.text(' Keep this exact\nline two '), findsOneWidget); expect(find.text('plan.md'), findsOneWidget); expect(find.text('report.csv'), findsOneWidget); - final role = tester.widget(find.text('User')); final theme = Theme.of(tester.element(find.byType(ChatMessageView))); expect(theme.brightness, Brightness.dark); - expect(role.style?.color, theme.colorScheme.onSurfaceVariant); - expect(role.style?.color?.computeLuminance(), greaterThan(0.4)); expect(tester.takeException(), isNull); }); @@ -86,14 +85,12 @@ void main() { await tester.pumpWidget(_host(_userRow(), cupertino: true, scale: 2)); await tester.pumpAndSettle(); - expect(find.text('User'), findsOneWidget); + expect(find.text('User'), findsNothing); expect(find.text(' Keep this exact\nline two '), findsOneWidget); expect(find.text('plan.md'), findsOneWidget); expect(find.text('report.csv'), findsOneWidget); final context = tester.element(find.byType(ChatMessageView)); expect(CupertinoTheme.of(context).brightness, Brightness.dark); - final role = tester.widget(find.text('User')); - expect(role.style?.color?.computeLuminance(), greaterThan(0.4)); expect(tester.takeException(), isNull); }, ); @@ -120,7 +117,8 @@ void main() { await tester.pumpWidget(_host(row, scale: 2)); await tester.pumpAndSettle(); - expect(find.text('Assistant'), findsOneWidget); + expect(find.text('Assistant'), findsNothing); + expect(find.bySemanticsLabel('Assistant message'), findsOneWidget); expect(find.text('private reasoning'), findsNothing); expect(find.textContaining('"command": "ls"'), findsNothing); expect(find.textContaining('"payload": 7'), findsNothing); @@ -318,4 +316,21 @@ void main() { expect(find.text('Rendered **markdown**'), findsOneWidget); expect(find.text('**markdown**'), findsNothing); }); + + testWidgets('a short user turn is a right-aligned bubble, not a full row', ( + tester, + ) async { + _phone(tester); + await tester.pumpWidget(_host(_userRow())); + await tester.pumpAndSettle(); + final row = tester.getRect(find.byType(ChatMessageView)); + final bubble = tester.getRect( + find.ancestor( + of: find.text('Ada phone'), + matching: find.byType(Material), + ).first, + ); + expect(bubble.width, lessThanOrEqualTo(row.width * 0.85 + 0.5)); + expect(bubble.right, closeTo(row.right, 1)); + }); } diff --git a/app/test/features/chat/ui/transcript/chat_unknown_user_part_test.dart b/app/test/features/chat/ui/transcript/chat_unknown_user_part_test.dart index 4b66bdd1..ed2e85ee 100644 --- a/app/test/features/chat/ui/transcript/chat_unknown_user_part_test.dart +++ b/app/test/features/chat/ui/transcript/chat_unknown_user_part_test.dart @@ -27,13 +27,7 @@ void main() { ), ), ); - final label = tester.widget(find.text('User')); - expect( - label.style!.fontWeight, - Theme.of( - tester.element(find.byType(ChatMessageView)), - ).textTheme.labelLarge!.fontWeight, - ); + expect(find.text('User'), findsNothing); expect(find.text('Recorded user text'), findsOneWidget); await tester.tap(find.text('Unrecognised part: future-content')); await tester.pumpAndSettle();