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.new({List<
ChatMessage> ? initialMessages, Future<List< onLoadMoreMessages(ChatMessage? lastMessage)?})ChatMessage> > - Creates a new chat messages controller.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isLoadingMore → bool
-
Whether more messages are currently being loaded.
no setter
-
messages
→ List<
ChatMessage> -
List of all chat messages, ordered from newest to oldest.
no setter
-
onLoadMoreMessages
→ Future<
List< Function(ChatMessage? lastMessage)?ChatMessage> > -
Callback function to load more messages when scrolling up.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showWelcomeMessage → bool
-
Whether to show the welcome message.
no setter
Methods
-
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.
-
clearMessages(
) → void - Clears all messages and shows the welcome message.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
inherited
-
handleExampleQuestion(
String question, ChatUser currentUser, ChatUser aiUser) → void - Handles an example question by creating and adding appropriate messages.
-
loadMore(
) → Future< void> - Loads more messages using the onLoadMoreMessages 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
-
setMessages(
List< ChatMessage> messages) → void - Replaces all existing messages with a new list.
-
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