Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions examples/simple_chat/lib/chat_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ sealed class ChatSession extends ChangeNotifier {
}

Future<void> _runRequest(Future<void> Function() body) async {
// The response streams in through `_updateAiMessage`, which starts a new
// bubble when `_currentAiMessage` is null and appends to that bubble
// otherwise. Clearing it here is what gives the coming response a bubble of
// its own. Every request runs through here, both typed messages and the
// ones a surface submits when the user taps a button, so a button's reply
// does not end up appended to the previous response.
_currentAiMessage = null;
_isProcessing = true;
Comment thread
polina-c marked this conversation as resolved.
notifyListeners();
Comment thread
polina-c marked this conversation as resolved.
try {
Expand Down Expand Up @@ -164,7 +171,6 @@ class TextOnlyChatSession extends ChatSession {
Future<void> sendMessage(String text) async {
if (text.isEmpty) return;

_currentAiMessage = null;
_addUserMessage(text);

await _runRequest(
Expand Down Expand Up @@ -236,9 +242,6 @@ class A2uiChatSession extends ChatSession {
Future<void> sendMessage(String text) async {
if (text.isEmpty) return;

// Reset current AI message so new response gets a new bubble
_currentAiMessage = null;

_addUserMessage(text);

await _runRequest(() => _transport.sendRequest(ChatMessage.user(text)));
Expand Down
Loading