InMemoryChatController class

A basic ChatController implementation that stores messages in memory.

This controller does not persist messages across app restarts. It includes UploadProgressMixin for upload progress tracking and ScrollToMessageMixin for programmatic scrolling.

Important: Ensures that all message IDs are unique during initialization and insertion to prevent issues with animations and state management.

Implemented types
Mixed-in types

Constructors

InMemoryChatController({List<Message>? messages})
Creates an in-memory chat controller. Optionally initializes with a list of messages.

Properties

hashCode int
The hash code for this object.
no setterinherited
messages List<Message>
Gets the current list of messages.
no setteroverride
operationsStream Stream<ChatOperation>
A stream that emits ChatOperation objects whenever the message list changes. UI components can listen to this stream to react to updates.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

attachScrollMethods({required ScrollToMessageId scrollToMessageId, required ScrollToIndex scrollToIndex}) → void
Attaches the scroll methods that will be used for scrolling operations. This is called automatically by ChatAnimatedList.
inherited
clearUploadProgress(String id) → void
Closes and removes the progress stream for the given message ID. Typically called when the upload is complete or cancelled.
inherited
detachScrollMethods() → void
Detaches the scroll methods when the widget is disposed.
inherited
dispose() → void
Releases resources used by the controller (e.g., closes streams).
override
disposeScrollMethods() → void
Disposes scroll resources. This should be called in the ChatController's dispose method.
inherited
disposeUploadProgress() → void
Disposes all active upload progress controllers. Should be called in the ChatController.dispose method.
inherited
getUploadProgress(String id) Stream<double>
Gets a stream that emits upload progress updates (0.0 to 1.0) for a given message ID.
inherited
insertAllMessages(List<Message> messages, {int? index, bool animated = true}) Future<void>
Inserts a list of messages into the chat, starting at the specified index.
override
insertMessage(Message message, {int? index, bool animated = true}) Future<void>
Inserts a new message into the list, optionally at a specific index.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeMessage(Message message, {bool animated = true}) Future<void>
Removes a specific message from the list. The message parameter is used to identify the message to be removed, typically by its id.
override
scrollToIndex(int index, {Duration duration = const Duration(milliseconds: 250), Curve curve = Curves.linearToEaseOut, double alignment = 0, double offset = 0}) Future<void>
Scrolls to a specific index in the message list.
inherited
scrollToMessage(MessageID messageId, {Duration duration = const Duration(milliseconds: 250), Curve curve = Curves.linearToEaseOut, double alignment = 0, double offset = 0}) Future<void>
Scrolls to a specific message by ID.
inherited
setMessages(List<Message> messages, {bool animated = true}) Future<void>
Replaces the entire message list with the provided messages.
override
toString() String
A string representation of this object.
inherited
updateMessage(Message oldMessage, Message newMessage) Future<void>
Replaces an oldMessage with a newMessage.
override
updateUploadProgress(String id, double progress) → void
Updates the upload progress for a specific message ID.
inherited

Operators

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