messages property

List<AssistMessage> messages
final

A list of AssistMessage objects that will be displayed in the chat interface.

Each message includes details such as the message text, timestamp, and author information.

AssistMessage.request message will be treated as a user request. AssistMessage.response message will be treated as a AI response.

List<AssistMessage> _messages = <AssistMessage>[];

void _generateAIResponse(String request) {
  // Connect to your preferred AI and get response for the request.
  String response = 'AI response'; // Replace with actual AI response.
  setState(() {
    _messages.add(AssistMessage.response(data: response));
  });
}

SfAIAssistView view = SfAIAssistView(
  messages: _messages,
  actionButton: AssistActionButton(
    onPressed: (String data) {
      _messages.add(AssistMessage.request(data: data));
      _generateAIResponse(data);
    },
  ),
);

Implementation

final List<AssistMessage> messages;