fix(chat): centre the pending dots on the activity text

The dots were period glyphs sitting on the baseline, so they read low
beside the label. They are now round dots sized from the surrounding
text, vertically centred with it and scaling with it.
This commit is contained in:
2026-10-30 23:54:22 +00:00
parent 4a85a12cf7
commit 6dbfdc6e64
2 changed files with 88 additions and 28 deletions
@@ -35,32 +35,58 @@ class _ChatResponsePendingState extends State<ChatResponsePending>
}
@override
Widget build(BuildContext context) => Semantics(
label: 'Assistant is responding',
liveRegion: true,
excludeSemantics: true,
child: AnimatedBuilder(
animation: _animation,
builder: (context, _) => Row(
mainAxisSize: MainAxisSize.min,
children: [
for (var index = 0; index < 3; index++)
Opacity(
opacity: MediaQuery.disableAnimationsOf(context)
? 1
: 0.35 +
0.65 *
(0.5 +
0.5 *
math.sin(
2 *
math.pi *
(_animation.value - index / 3),
)),
child: const Text('.'),
),
],
Widget build(BuildContext context) {
// Round dots sized from the surrounding text, so they sit on the text's
// middle (a period glyph sits on the baseline and reads low) and follow
// text scaling and colour.
final style = DefaultTextStyle.of(context).style;
final fontSize = MediaQuery.textScalerOf(
context,
).scale(style.fontSize ?? 14);
final dot = fontSize * 0.3;
final color = style.color ?? const Color(0xFF808080);
return Semantics(
label: 'Assistant is responding',
liveRegion: true,
excludeSemantics: true,
child: SizedBox(
key: const Key('chat-response-pending-dots'),
height: fontSize,
child: AnimatedBuilder(
animation: _animation,
builder: (context, _) => Row(
mainAxisSize: MainAxisSize.min,
children: [
for (var index = 0; index < 3; index++)
Padding(
padding: EdgeInsetsDirectional.only(
start: index == 0 ? 0 : dot * 0.6,
),
child: Opacity(
opacity: MediaQuery.disableAnimationsOf(context)
? 1
: 0.35 +
0.65 *
(0.5 +
0.5 *
math.sin(
2 *
math.pi *
(_animation.value - index / 3),
)),
child: DecoratedBox(
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
),
child: SizedBox.square(dimension: dot),
),
),
),
],
),
),
),
),
);
);
}
}
@@ -194,8 +194,42 @@ void main() {
),
);
await tester.pumpAndSettle();
expect(find.text('.'), findsNWidgets(3));
// Three steady dots, all fully drawn, with no animation scheduled.
final opacities = tester
.widgetList<Opacity>(
find.descendant(
of: find.byType(ChatResponsePending),
matching: find.byType(Opacity),
),
)
.map((widget) => widget.opacity);
expect(opacities, [1, 1, 1]);
expect(find.bySemanticsLabel('Assistant is responding'), findsOneWidget);
expect(tester.binding.hasScheduledFrame, isFalse);
});
for (final cupertino in [false, true]) {
testWidgets('the pending dots sit on the activity text\'s middle '
'($cupertino)', (tester) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway, cupertino: cupertino);
await _send(tester);
final dots = tester.getRect(
find.byKey(const Key('chat-response-pending-dots')),
);
final label = tester.getRect(find.textContaining('Thinking'));
expect(dots.center.dy, closeTo(label.center.dy, 1));
expect(dots.height, lessThanOrEqualTo(label.height));
// Round dots, not baseline glyphs.
expect(
find.descendant(
of: find.byType(ChatResponsePending),
matching: find.text('.'),
),
findsNothing,
);
});
}
}