Show an animated assistant bubble before response tokens
This commit is contained in:
@@ -9,6 +9,7 @@ import '../../domain/chat_tool_calls.dart';
|
||||
import 'chat_tool_calls_view.dart';
|
||||
import 'chat_reasoning_chip.dart';
|
||||
import 'native_disclosure.dart';
|
||||
import 'chat_response_pending.dart';
|
||||
|
||||
/// Builds an assistant text part; the default keeps the server's text exactly.
|
||||
typedef ChatMessageTextBuilder = Widget Function(BuildContext, String);
|
||||
@@ -265,6 +266,9 @@ class ChatMessageView extends StatelessWidget {
|
||||
KeyedSubtree(key: _partKey(part, index, seen), child: widget),
|
||||
);
|
||||
}
|
||||
if (widgets.isEmpty && row['streaming'] == true) {
|
||||
widgets.add(const ChatResponsePending());
|
||||
}
|
||||
return widgets;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
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) => 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('.'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user