onSuggestionItemSelected property
Optional callback function that will be executed when the suggestion is selected.
The onSuggestionItemSelected callback is triggered when the user selects a suggestion from the suggestion list. This callback provides details about the selected suggestion, suggestion index, and the message index.
When a suggestion is selected, you can use this callback to update the UI to reflect the selected state of the suggestion and the selected suggestion is added as a new message in the conversation area.
@override
Widget build(BuildContext context) {
return SfChat(
onSuggestionItemSelected:
(selected, messageIndex, suggestion, suggestionIndex) {
setState(() {
_messages[messageIndex].suggestions![messageIndex] =
suggestion.copyWith(selected: true);
_messages.add(
ChatMessage(
text: _messages[messageIndex]
.suggestions![messageIndex]
.data!,
time: DateTime.now(),
author: const ChatAuthor(
id: 'a2c4-56h8-9x01-2a3d',
name: 'Incoming user name',
),
),
);
});
},
);
}
Implementation
final ChatSuggestionItemSelectedCallback? onSuggestionItemSelected;