Files
pipelines/app/lib/features/chat/ui/transcript/chat_response_pending.dart
T
alan 6dbfdc6e64 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.
2026-10-30 23:54:22 +00:00

93 lines
2.9 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/widgets.dart';
/// A local animation inside the normal assistant bubble, before answer text.
/// It never rebuilds the transcript or changes its scroll position on a tick.
class ChatResponsePending extends StatefulWidget {
const ChatResponsePending({super.key});
@override
State<ChatResponsePending> createState() => _ChatResponsePendingState();
}
class _ChatResponsePendingState extends State<ChatResponsePending>
with SingleTickerProviderStateMixin {
late final AnimationController _animation = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1200),
);
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (MediaQuery.disableAnimationsOf(context)) {
_animation.stop();
} else {
_animation.repeat();
}
}
@override
void dispose() {
_animation.dispose();
super.dispose();
}
@override
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),
),
),
),
],
),
),
),
);
}
}