ChatMessage class

Represents a chat message.

The ChatMessage class stores the details of a message within a chat system, including the text content, the time when the message was sent, the author who sent the message, list of suggestion items for a message, and the suggestion settings to customize the suggestion items.

Example:

@override
Widget build(BuildContext context) {
  return SfChat(
    messages: [
      ChatMessage(
        text:
         'Hi, I have planned to go on a trip. Can you suggest some places?',
        time: DateTime.now(),
        author: const ChatAuthor(id: '123-001', name: 'Chat A'),
        suggestions: <ChatMessageSuggestion>[
          ChatMessageSuggestion(
            data: 'Paris',
          ),
          ChatMessageSuggestion(
            data: 'Tokyo',
          ),
          ChatMessageSuggestion(
            data: 'New York',
          ),
          ChatMessageSuggestion(
            data: 'London',
          ),
        ],
        suggestionSettings: ChatSuggestionSettings(
          backgroundColor: Colors.grey[300],
          itemBackgroundColor: WidgetStateProperty.resolveWith<Color>(
            (states) {
              if (states.contains(WidgetState.hovered)) {
                return Colors.grey[400]!;
              }
              return Colors.grey;
            },
          ),
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(
              Radius.circular(4.0),
            ),
          ),
          itemShape: WidgetStateProperty.resolveWith<ShapeBorder>(
            (Set<WidgetState> states) {
              if (states.contains(WidgetState.hovered)) {
                return RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20),
                );
              }
              return RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(5),
              );
            },
          ),
        textStyle: WidgetStateProperty.resolveWith<TextStyle?>(
          (Set<WidgetState> states) {
            if (states.contains(WidgetState.disabled)) {
              return const TextStyle(fontSize: 16);
            }
            return const TextStyle(fontSize: 14);
          },
         ),
          margin: const EdgeInsets.all(10),
          itemPadding:
              const EdgeInsets.symmetric(horizontal: 12, vertical: 8.0),
          orientation: Axis.horizontal,
          itemOverflow: ChatSuggestionOverflow.scroll,
        ),
      ),
    ],
  );
}

Constructors

ChatMessage({required String text, required DateTime time, required ChatAuthor author, List<ChatMessageSuggestion>? suggestions, ChatSuggestionSettings? suggestionSettings})
Creates a ChatMessage instance with the given text, time, author and optional suggestions and suggestionSettings.
const

Properties

author → ChatAuthor
Author of the message.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
suggestions → List<ChatMessageSuggestion>?
List of suggestion items for the message.
final
suggestionSettings → ChatSuggestionSettings?
Settings for customizing the appearance and layout of message suggestions in ChatMessage.
final
text → String
Content of the message.
final
time → DateTime
Timestamp when the message was sent.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited