ChatMessage class

Represents a message in a chat conversation.

This class encapsulates the properties and behavior of a chat message, including its unique identifier, origin (user or LLM), text content, and any attachments.

A message is a ChangeNotifier: it notifies as its streamed text and transient turn state (toolActivity, isGenerating, usage) change, so only the live bubble rebuilds per token while the provider's coarser notifications cover structural history changes.

Inheritance

Constructors

ChatMessage({required MessageOrigin origin, required String? text, required Iterable<Attachment> attachments, String? thinking})
Constructs a ChatMessage instance.
ChatMessage.fromJson(Map<String, dynamic> map)
Converts a JSON map representation to a ChatMessage.
factory
ChatMessage.llm()
Factory constructor for creating an LLM-originated message.
factory
ChatMessage.user(String text, Iterable<Attachment> attachments)
Factory constructor for creating a user-originated message.
factory

Properties

attachments Iterable<Attachment>
Any attachments associated with the message.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isGenerating bool
Whether the provider is currently streaming this message's turn.
getter/setter pair
origin MessageOrigin
The origin of the message (user or LLM).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
text String?
Text content of the message.
no setter
thinking String?
The model's reasoning ("thinking") for this turn, when it produced any.
no setter
toolActivity String?
Name(s) of the tools the model is currently running to produce this message, or null when no tool is in flight.
getter/setter pair
turnDuration Duration?
Total wall-clock duration of the turn, set once the turn completes.
getter/setter pair
turnStartedAt DateTime?
Wall-clock start of the turn that produced this message, when known.
getter/setter pair
usage ↔ UsageDetails?
Token usage of the model turn that produced this message, when known.
getter/setter pair

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
addUsage(UsageDetails details) → void
Accumulates details into usage for a multi-request turn.
append(String text) → void
Appends additional text to the existing message content.
appendThinking(String text) → void
Appends a streamed reasoning delta to thinking.
dispose() → void
Discards any resources used by the object.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toJson() Map<String, dynamic>
Converts a ChatMessage to a JSON map representation.
toString() String
A string representation of this object.
override

Operators

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