ChatMessage class
Represents a single message in a chat conversation.
This class is immutable and contains all the necessary information about a chat message including its content, sender type, and timestamp.
Example:
final message = ChatMessage(
id: '123',
content: 'Hello, how are you?',
isUser: true,
timestamp: DateTime.now(),
);
- Annotations
Constructors
- ChatMessage.new({required String id, required String content, required bool isUser, required DateTime timestamp})
-
Creates a new chat message.
const
-
ChatMessage.fromJson(Map<
String, dynamic> json) -
Creates a ChatMessage from a JSON representation.
factory
Properties
- content → String
-
The text content of the message.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- id → String
-
Unique identifier for this message.
final
- isUser → bool
-
Whether this message is from the user (true) or AI (false).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timestamp → DateTime
-
When this message was sent.
final
Methods
-
copyWith(
{String? id, String? content, bool? isUser, DateTime? timestamp}) → ChatMessage - Creates a copy of this message with some fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Converts this message to a JSON representation.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override