ChatMessagesController class
Controller for managing chat messages and their states.
This controller handles message operations such as adding, updating, and loading more messages. It also manages the welcome message state and loading states for pagination.
- Inheritance
-
- Object
- ChangeNotifier
- ChatMessagesController
Constructors
-
ChatMessagesController({List<
ChatMessage> ? initialMessages, PaginationConfig paginationConfig = const PaginationConfig(), Future<List< onLoadMoreMessages(ChatMessage? lastMessage)?, bool showWelcomeMessage = false, ScrollBehaviorConfig? scrollBehaviorConfig})ChatMessage> > - Creates a new chat messages controller.
Properties
- currentPage → int
-
Current page of pagination
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- hasMoreMessages → bool
-
Whether there are more messages to load.
no setter
- isCurrentlyStreaming → bool
-
Whether a message is currently being streamed
no setter
- isLoadingMore → bool
-
Whether more messages are currently being loaded.
no setter
-
messages
→ List<
ChatMessage> -
List of all chat messages.
If paginationConfig.reverseOrder is true, newest messages are first (index 0).
If paginationConfig.reverseOrder is false, oldest messages are first (index 0).
no setter
- mounted → bool
-
no setter
- paginationConfig → PaginationConfig
-
Configuration for pagination behavior
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollBehaviorConfig ↔ ScrollBehaviorConfig
-
Get the current scroll behavior configuration
getter/setter pair
- showWelcomeMessage ↔ bool
-
Whether to show the welcome message.
getter/setter pair
Methods
-
addAgentMessage(
ChatMessage message) → void -
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
addMessage(
ChatMessage message) → void - Adds a new message to the chat.
-
addMessages(
List< ChatMessage> messages) → void - Adds multiple messages to the chat at once.
-
clearMessages(
) → void - Clears all messages and shows the welcome message.
-
dispose(
) → void -
Discards any resources used by the object.
override
-
forceScrollToFirstMessageInChain(
String responseId) → void - Find first message in a response chain and force scroll to it with extra reliability
-
forceScrollToTop(
) → void - Scrolls to a specific message directly with maximum reliability This is a more direct approach for ensuring the first message is visible
-
getMessageId(
ChatMessage message) → String - Public method to get a message ID (for testing/debugging)
-
handleExampleQuestion(
String question, ChatUser currentUser, ChatUser aiUser) → void - Handles an example question by creating and adding appropriate messages.
-
hideWelcomeMessage(
) → void -
loadMore(
Future< List< loadCallback()?) → Future<ChatMessage> >void> - Loads more messages using the provided callback.
-
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
-
resetPagination(
) → void - Resets pagination state
-
scrollToBottom(
[Duration? duration, Curve? curve]) → void - Scrolls to the bottom of the message list
-
scrollToBottomNoAnimate(
) → void -
scrollToMessage(
String messageId) → void - Scrolls to a specific message by ID with improved position calculation
-
scrollToMessageObject(
ChatMessage message) → void - Scrolls to a specific message directly
-
scrollToTopNoAnimate(
) → void -
setMessages(
List< ChatMessage> messages) → void - Replaces all existing messages with a new list.
-
setScrollController(
ScrollController controller) → void - Sets the scroll controller for auto-scrolling
-
toString(
) → String -
A string representation of this object.
inherited
-
updateMessage(
ChatMessage message) → void - Updates an existing message or adds it if not found.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited