ChatController class
Controller based on ChangeNotifier, compatible with Provider.
Manages:
- Message feed
- Unread count
- Active reply
- Errors
- Sending messages
- Deletion
- User blocking
- Pagination
- Auto scroll
- Mark as read
Example:
final controller = ChatController(
service: chatService,
chatId: 'chat-123',
currentUserId: 'user-456',
);
- Inheritance
-
- Object
- ChangeNotifier
- ChatController
Constructors
- ChatController({required ChatService service, required String chatId, required String currentUserId})
- Creates a new ChatController.
Properties
-
blockedUsers
→ Set<
String> -
Set of blocked user IDs.
no setter
- chatId → String
-
ID of the chat.
final
- currentUserId → String
-
ID of the current user.
final
- error → String?
-
Current error message, if any.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- hasMore → bool
-
Whether there are more messages to load.
no setter
- isLoading → bool
-
Whether messages are currently loading.
no setter
-
messages
→ List<
ChatMessage> -
List of all messages.
no setter
- replyingTo → ChatMessage?
-
Message currently being replied to, if any.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- service → ChatService
-
The chat service implementation.
final
- unreadCount → int
-
Number of unread messages.
no setter
-
visibleMessages
→ List<
ChatMessage> -
Filters messages removing those from blocked users.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
blockUser(
String userId) → Future< void> - Blocks a user.
-
deleteMessage(
ChatMessage message) → Future< void> - Deletes a message.
-
dispose(
) → void -
Discards any resources used by the object.
override
-
loadMore(
) → Future< void> - Loads more messages (pagination).
-
markAsRead(
) → Future< void> - Marks messages as read.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
reloadMessages(
) → void - Reloads messages (used for retry).
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
sendMessage(
String text) → Future< void> - Sends a message.
-
setReplyingTo(
ChatMessage? message) → void - Sets the message being replied to.
-
toString(
) → String -
A string representation of this object.
inherited
-
unblockUser(
String userId) → Future< void> - Unblocks a user.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited