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:
@@ -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),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user