ChatService class

Core service for chat functionality

Inheritance

Properties

chatRooms List<ChatRoom>
Available chat rooms
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isLoading bool
Whether data is currently loading
no setter
isReceiverOnline bool
Whether the receiver is currently online
no setter
isReceiverTyping bool
Whether the receiver is currently typing
no setter
isSocketConnected bool
Whether the socket is connected
no setter
lastSeen DateTime?
Last seen timestamp for the receiver
no setter
messages List<ChatMessage>
Current messages for the active chat
no setter
receiverId String
Current receiver ID
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addEventListener(ChatEventType eventType, String id, Function callback) → void
Add an event listener with a unique identifier
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
deleteMessage(String messageId) Future<bool>
Delete a message (mark as deleted on the server)
disconnectSocket() → void
Disconnects socket safely
dispose() → void
Clean up resources
override
emitCustomEvent(String eventName, dynamic data) → void
Emit a custom socket event
fullDisconnect() → void
Disconnects completely (for logout)
getMessageById(String messageId) ChatMessage?
Get chat message by ID
getRoomId(String user1, String user2) String
Gets a room ID from two user IDs
handleMessageStatusUpdate(Map<String, dynamic> data) → void
Handles message status updates
initChat(String receiverId) Future<void>
Initializes socket for chat with specific user
initGlobalConnection() Future<void>
initialize() Future<void>
Initializes the chat service
joinChat() → void
Joins a chat room
leaveChat(String receiverId) → void
Leaves the current chat but maintains the socket connection
loadChatRooms() Future<List<ChatRoom>>
Loads chat rooms for the user
loadMessages({int page = 1, int limit = 20, String searchText = ""}) Future<List<ChatMessage>>
Loads messages for the current chat
loadMoreMessages({required int page, int limit = 20, String searchText = ""}) Future<List<ChatMessage>>
Loads more messages (pagination)
logSocketState() → void
Logs current socket state for debugging
markMessagesAsRead() Future<void>
Marks all 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
receiveMessage(Map<String, dynamic> messageData) → void
Processes a received message
refreshGlobalConnection() → void
Refreshes global connection
registerCustomSocketEvents(Map<String, dynamic Function(dynamic)> customEvents) → void
removeAllEventListeners(ChatEventType eventType) → void
Remove all event listeners for a specific event type
removeEventListener(ChatEventType eventType, String id) → void
Remove an event listener by its identifier
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, {String? attachmentUrl, String? attachmentName, String? attachmentType}) Future<ChatMessage>
Sends a message to the current receiver
sendTypingIndicator(bool isTyping) → void
Sends typing indicator
setApiHandlers(ChatApiHandlers handlers) → void
Set custom API handlers
setDebugMode(bool enabled) → void
Set debug mode
setReceiverId(String val) → void
Sets the receiver ID for the current chat
setSocketEventConfig(SocketEventConfig config) → void
Set custom socket event configuration
toString() String
A string representation of this object.
inherited
triggerCustomEvent(String eventName, dynamic data) → void
Trigger a custom event
updateConfig(ChatConfig config) → void
Update ChatConfig instance reference
updateUserStatus(bool isOnline) → void
Updates user's online status

Operators

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

Static Properties

instance ChatService
Singleton instance
no setter