Add _isWaitingForAgentResponse Property to ChatViewModel

A new property named _isWaitingForAgentResponse has been introduced to the ChatViewModel class to track the loading state when waiting for the agent's response. This boolean property is set to true when a chat message is being sent and reverts to false upon completion, whether successful or not. The notifyListeners() method is invoked to update the UI accordingly. This enhancement facilitates the display of a loading indicator, offering users visual feedback during the wait time for agent responses.
This commit is contained in:
hunteraraujo
2023-09-28 13:09:05 -07:00
parent a438619177
commit f3210fba96

View File

@@ -10,6 +10,10 @@ class ChatViewModel with ChangeNotifier {
List<Chat> _chats = [];
String? _currentTaskId;
bool _isWaitingForAgentResponse = false;
bool get isWaitingForAgentResponse => _isWaitingForAgentResponse;
bool _isContinuousMode = false;
bool get isContinuousMode => _isContinuousMode;
@@ -108,6 +112,9 @@ class ChatViewModel with ChangeNotifier {
print("Error: Task ID is not set.");
return;
}
_isWaitingForAgentResponse = true;
notifyListeners();
try {
// Create the request body for executing the step
StepRequestBody requestBody = StepRequestBody(input: message);
@@ -163,6 +170,9 @@ class ChatViewModel with ChangeNotifier {
// TODO: Bubble up errors to UI
print("Error sending chat: $error");
// TODO: Handle additional error scenarios or log them as required
} finally {
_isWaitingForAgentResponse = false;
notifyListeners();
}
}