CometChat class

Flutter wrapper for using CometChat SDK.

for more information on how to use wrapper effectively.

Constructors

CometChat(String appId, {@Deprecated('The authKey is deprecated due to security concerns. Please use [otherMethod] instead.') String? authKey, String region = 'us'})
Constructor for creating CometChat object appId refers to your CometChat App ID. region The region where the app was created.

Properties

appId → String
final
authKey → String?
Use this only for testing purpose
final
hashCode → int
The hash code for this object.
no setterinherited
region → String
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

nativeStream ↔ Stream?
This is stream channel to receiver messages
getter/setter pair

Static Methods

acceptCall(String sessionID, {required dynamic onSuccess(Call call)?, required dynamic onError(CometChatException excep)}) → void
Accepts an incoming call.
addAIAssistantListener(String listenerId, AIAssistantListener listenerClass) → void
Call-SDK-changes
addCallListener(String listenerId, CallListener listenerClass) → void
Call-SDK-changes
addConnectionListener(String listenerId, ConnectionListener listenerClass) → void
The ConnectionListener class provides you with all the status of the connection to CometChat web-socket servers
addConversationListener(String listenerId, ConversationListener listener) → void
Adds a ConversationListener for conversation pin/unpin events (Pin Conversation, ENG-37600).
addGroupListener(String listenerId, GroupListener listenerClass) → void
The GroupListener class provides you with all the real-time events related to groups
addloginListener(String listenerId, LoginListener listenerClass) → void
The LoginListener class provides you with all the real-time updates for the login and logout events
addMembersToGroup({required String guid, required List<GroupMember> groupMembers, required dynamic onSuccess(Map<String?, String?> result)?, required dynamic onError(CometChatException excep)?}) → Future<Map<String?, String?>?>
Adds members to a group.
addMessageListener(String listenerId, MessageListener listenerClass) → void
For every activity or fragment you wish to receive messages in, you need to register the MessageListener
addNotificationFeedListener(String listenerId, NotificationFeedListener listener) → void
Register a NotificationFeedListener for real-time notification feed events.
addReaction(int messageId, String reaction, {required dynamic onSuccess(BaseMessage)?, required dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Add a reaction to a message.
addUserListener(String listenerId, UserListener listenerClass) → void
The UserListener class provides you with live events related to users listenerId unique id for listener
askBot(String receiverId, String receiverType, String botId, String question, {Map? configuration, required dynamic onSuccess(String conversationSummary), required dynamic onError(CometChatException excep)}) → Future<void>
Ask an AI bot a question in the context of a conversation.
banGroupMember({required String guid, required String uid, required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Bans a member from a group.
blockUser(List<String>? uids, {required dynamic onSuccess(Map<String, dynamic> map)?, required dynamic onError(CometChatException excep)?}) → Future<Map<String, dynamic>?>
Block a user from sending logged-in user any messages.
callExtension(String slug, String requestType, String endPoint, Map<String, dynamic>? body, {required dynamic onSuccess(Map<String, dynamic> map)?, required dynamic onError(CometChatException excep)?}) → Future<Map<String, dynamic>?>
can call any extension
clearActiveCall() → Future<void>
Clears the locally stored active call session.
connect({dynamic onSuccess(String result)?, dynamic onError(CometChatException excep)?}) → Future<Null>
will establish the Web-socket connections manually
createGroup({required Group group, required dynamic onSuccess(Group group)?, required dynamic onError(CometChatException excep)?}) → Future<Group?>
Returns a Group object after creating in CometChat API.
createGroupWithMembers({required Group group, required List<GroupMember> groupMembers, List<String> bannedUserIds = const [], dynamic onSuccess(Group group)?, dynamic onError(CometChatException excep)?}) → Future<Group?>
Creates a group in CometChat along with initial members and returns the created Group.
createUploadFileRequest(String receiverId, String receiverType) → UploadFileRequest
Creates an UploadFileRequest scoped to one destination and one batch.
createUser(User user, String authKey, {required dynamic onSuccess(User user)?, required dynamic onError(CometChatException excep)?}) → Future<User?>
Method returns user after creation in cometchat environment
deleteConversation(String conversationWith, String conversationType, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Method deletes the conversation only for the logged-in user.
deleteGroup(String guid, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Deletes a group.
deleteMessage(int messageId, {required dynamic onSuccess(BaseMessage)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Deletes the message with specified messageId.
disconnect({dynamic onSuccess(String result)?, dynamic onError(CometChatException excep)?}) → Future<Null>
will disable the Web-socket connections manually
editMessage(BaseMessage message, {required dynamic onSuccess(BaseMessage)?, required dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
edit a message, you can use the editMessage() method
endCall(String sessionID, {int? joinedAt, required dynamic onSuccess(Call call)?, required dynamic onError(CometChatException excep)}) → void
Ends an ongoing call.
endTyping({required String receiverUid, required String receiverType}) → Future<void>
method to inform the receiver that the logged in user has ended typing.
flagMessage(int messageId, FlagDetail detail, {dynamic onSuccess(String result)?, dynamic onError(CometChatException excep)?}) → Future<String?>
Flags a message for content moderation.
getActiveCall() → Future<Call?>
Gets the currently active call session.
getConnectionStatus() → Future<String>
Get the current WebSocket connection status.
getConversation(String conversationWith, String conversationType, {required dynamic onSuccess(Conversation conversation)?, required dynamic onError(CometChatException excep)?}) → Future<Conversation?>
In order to fetch a specific conversation
getConversationFromMessage(BaseMessage message, {required dynamic onSuccess(Conversation conversation)?, required dynamic onError(CometChatException excep)?}) → Future<Conversation?>
get the conversation object from message object.
getConversationStarter(String receiverId, String receiverType, {Map? configuration, required dynamic onSuccess(List<String> conversationStarters), required dynamic onError(CometChatException excep)}) → Future<void>
Get AI-generated conversation starter suggestions.
getConversationSummary(String receiverId, String receiverType, {Map? configuration, required dynamic onSuccess(String conversationSummary), required dynamic onError(CometChatException excep)}) → Future<void>
Get AI-generated summary of a conversation.
getConversationUpdateSettings({dynamic onSuccess(ConversationUpdateSettings)?, dynamic onError(CometChatException excep)?}) → Future<ConversationUpdateSettings>
Retrieves the ConversationUpdateSettings object to enable or disable certain features.
getFlagReasons({dynamic onSuccess(List<FlagReason> reasons)?, dynamic onError(CometChatException excep)?}) → Future<List<FlagReason>?>
Retrieves the list of flag reasons available for reporting content.
getGroup(String guid, {required dynamic onSuccess(Group group)?, required dynamic onError(CometChatException excep)?}) → Future<Group?>
Gets group details.
getLastDeliveredMessageId({dynamic onSuccess(int lastMessageId)?}) → Future<int?>
Get last delivered message ID.
getLoggedInUser({dynamic onSuccess(User user)?, dynamic onError(CometChatException excep)?}) → Future<User?>
Returns logged in User Object
getMaxAttachmentCount() → int
The maximum number of attachments allowed in a single message (file.count.max, default 10), from the cached app settings — falling back to the documented client default when the key is absent. Validate the attachment count against this before starting an upload.
getMaxAttachmentSize() → int
The maximum size, in bytes, allowed per attachment (file.size.max, default 100 MB), from the cached app settings — falling back to the documented client default when the key is absent. Size is validated per file only; there is no per-message aggregate cap.
getMessageDetails(int messageId, {dynamic onSuccess(BaseMessage)?, dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Fetches a single message by messageId.
getMessageReceipts(int messageId, {required dynamic onSuccess(List<MessageReceipt> messageReceipt)?, required dynamic onError(CometChatException excep)?}) → Future<List<MessageReceipt>?>
Method to get message receipts.
getNotificationFeedItem(String id, {required dynamic onSuccess(NotificationFeedItem feedItem)?, required dynamic onError(CometChatException excep)?}) → Future<NotificationFeedItem?>
Fetches a single NotificationFeedItem by its ID.
getNotificationFeedUnreadCount({required dynamic onSuccess(int lastMessageId)?, required dynamic onError(CometChatException excep)?}) → Future<int?>
Gets the unread count for the notification feed.
getOnlineGroupMemberCount(List<String> guids, {required dynamic onSuccess(Map<String, int> result)?, required dynamic onError(CometChatException excep)?}) → Future<Map<String, int>?>
get the total count of online users in particular groups Get online member count for multiple groups.
getOnlineUserCount({required dynamic onSuccess(int lastMessageId)?, required dynamic onError(CometChatException excep)?}) → Future<int?>
get the total count of online users for your app
getPinnedConversationsLimit() → int?
Max user-pinned conversations (features.ux.conversations.pinned.limit on the /me payload). Same absence semantics as getPinnedMessagesLimit.
getPinnedMessagesLimit() → int?
Max user-pinned messages per conversation (features.ux.messages.pinned.limit on the /me payload).
getSavedMessagesLimit() → int?
Max saved messages per user (features.ux.messages.saved.limit on the /me payload). Same absence semantics as getPinnedMessagesLimit; the cap error is ERR_SAVED_MESSAGES_LIMIT_EXCEEDED.
getSmartReplies(String receiverId, String receiverType, {Map? configuration, required dynamic onSuccess(HashMap<String, String>), required dynamic onError(CometChatException excep)}) → Future<void>
Get AI-generated smart reply suggestions for a conversation.
getUnreadMessageCount({bool? hideMessagesFromBlockedUsers, dynamic onSuccess(Map<String, Map<String, int>> message)?, dynamic onError(CometChatException excep)?}) → Future<Map<String, Map<String, int>>?>
Gives count of unread messages for every one-on-one and group conversation.
getUnreadMessageCountForAllGroups({bool? hideMessagesFromBlockedUsers, dynamic onSuccess(Map<String, int> result)?, dynamic onError(CometChatException excep)?}) → Future<Map<String, int>?>
Gives count of unread messages for every one-on-one and group conversation.
getUnreadMessageCountForAllUsers({bool? hideMessagesFromBlockedUsers, dynamic onSuccess(Map<String, int> result)?, dynamic onError(CometChatException excep)?}) → Future<Map<String, int>?>
Gives count of unread messages for every one-on-one and group conversation.
getUnreadMessageCountForGroup({required String guid, bool? hideMessagesFromBlockedUsers, dynamic onSuccess(Map<String, int> result)?, dynamic onError(CometChatException excep)?}) → Future<Map<String, int>?>
Gives count of unread messages for every one-on-one and group conversation.
getUser(String uid, {required dynamic onSuccess(User user)?, required dynamic onError(CometChatException excep)?}) → Future<User?>
Retrieve Particular User Details
getUserAuthToken() → Future<String?>
Get the current user's auth token.
init(String appId, AppSettings appSettings, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
method initializes the settings required for CometChat
initializetestmessageStream() → void
@Deprecated - Platform channel stream initialization This method is deprecated and will be removed in a future version. Use native Dart stream subscriptions via _setupNativeStreamSubscriptions() instead.
initiateCall(Call call, {required dynamic onSuccess(Call call)?, required dynamic onError(CometChatException excep)}) → void
Initiates a call to a user or group.
isAIFeatureEnabled(String feature, {required dynamic onSuccess(bool isEnabled), required dynamic onError(CometChatException excep)}) → Future<void>
Check if a specific AI feature is enabled.
isExtensionEnabled(String extensionId, {dynamic onSuccess(bool)?, dynamic onError(CometChatException excep)?}) → Future<bool>
Checks if a CometChat extension is enabled.
isPinConversationEnabled() → bool
Whether the Pin Conversation feature is enabled (features.ux.conversations.pinned.enabled).
isPinMessageEnabled() → bool
Whether the Pin Message feature is enabled (features.ux.messages.pinned.enabled).
isSaveMessageEnabled() → bool
Whether the Save Message feature is enabled (features.ux.messages.saved.enabled).
joinedAtForSession(String sessionID) → int
joinedAt in epoch seconds for sessionID, taken from the call cached by initiateCall / acceptCall.
joinGroup(String guid, String groupType, {String password = '', required dynamic onSuccess(Group group)?, required dynamic onError(CometChatException excep)?}) → Future<Group?>
Joins an existing group.
kickGroupMember({required String guid, required String uid, required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Kicks a member from a group.
leaveGroup(String guid, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Leaves a group.
loadPubspecYaml() → Future<String>
login(String uid, String authKey, {required dynamic onSuccess(User user)?, required dynamic onError(CometChatException excep)?}) → Future<User?>
Use this function only for testing purpose. For production, use loginWithAuthToken
loginWithAuthToken(String authToken, {required dynamic onSuccess(User user)?, required dynamic onError(CometChatException excep)?}) → Future<User?>
Returns a User object after login in CometChat API.
logout({required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Method to log out the user from CometChat
markAsDelivered(BaseMessage message, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Mark the messages for a particular conversation as delivered .
markAsInteracted(int messageId, String interactedElementId, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Messages elements can be marked as interacted.
markAsRead(BaseMessage baseMessage, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Messages for both user and group conversations can be marked as read using this method.
markConversationAsDelivered(String conversationWithId, String conversationType, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Marks all messages in a conversation as delivered.
markConversationAsRead(String conversationWithId, String conversationType, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Marks all messages in a conversation as read.
markFeedItemAsDelivered(NotificationFeedItem feedItem, {required dynamic onSuccess(void result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Marks a single NotificationFeedItem as delivered.
markFeedItemAsRead(NotificationFeedItem feedItem, {required dynamic onSuccess(void result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Marks a single NotificationFeedItem as read.
markFeedItemsAsDelivered(List<NotificationFeedItem> feedItems, {required dynamic onSuccess(void result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Marks multiple NotificationFeedItems as delivered (batch).
markMessageAsUnread(BaseMessage baseMessage, {required dynamic onSuccess(Conversation conversation)?, required dynamic onError(CometChatException excep)?}) → Future<Conversation?>
Marks a BaseMessage as unread.
markPushNotificationClicked(PushNotification pushNotification, {required dynamic onSuccess(void result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Marks a push notification as clicked.
markPushNotificationDelivered(PushNotification pushNotification, {required dynamic onSuccess(void result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Marks a push notification as delivered.
onTypingIndicator() → Stream<TypingIndicator>
Returns a stream of TypingIndicator events for real-time typing status.
pinConversation(String conversationWith, String conversationType, {dynamic onSuccess(Conversation conversation)?, dynamic onError(CometChatException excep)?}) → Future<Conversation?>
Pin the logged-in user's conversation with a user or group so it surfaces at the top of the conversations list.
ping({required Function? onSuccess, required dynamic onError(CometChatException excep)?}) → Future<void>
Manual ping to check WebSocket connection.
pinMessage(int messageId, {dynamic onSuccess(BaseMessage)?, dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Pin a message to its conversation.
registerTokenForPushNotification(String token, {required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Registers the obtained FCM Token which will be used by the CometChat server to send message via push notification.
rejectCall(String sessionID, String status, {required dynamic onSuccess(Call call)?, required dynamic onError(CometChatException excep)}) → void
Rejects an incoming call.
removeAIAssistantListener(String listenerId) → void
Call-SDK-changes
removeCallListener(String listenerId) → void
Call-SDK-changes
removeConnectionListener(String listenerId) → void
Remove Connection Listener
removeConversationListener(String listenerId) → void
Removes a previously registered ConversationListener. Call in dispose().
removeGroupListener(String listenerId) → void
Remove Group Listener
removeLoginListener(String listenerId) → void
Remove Login Listener
removeMessageListener(String listenerId) → void
To remove message listener
removeNotificationFeedListener(String listenerId) → void
Remove a previously registered NotificationFeedListener.
removeReaction(int messageId, String reaction, {required dynamic onSuccess(BaseMessage)?, required dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Remove a reaction from a message.
removeUserListener(String listenerId) → void
Remove User Listener
reportFeedEngagement(NotificationFeedItem feedItem, String interactionString, {required dynamic onSuccess(void result)?, required dynamic onError(CometChatException excep)?}) → Future<void>
Reports engagement for a NotificationFeedItem with a given interaction string.
saveMessage(int messageId, {dynamic onSuccess(BaseMessage)?, dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Save (bookmark) a message for the logged-in user.
sendCustomMessage(CustomMessage message, {required dynamic onSuccess(CustomMessage message)?, required dynamic onError(CometChatException excep)?}) → Future<CustomMessage?>
send custom messages which are neither text nor media messages.
sendInteractiveMessage(InteractiveMessage message, {required dynamic onSuccess(InteractiveMessage message)?, required dynamic onError(CometChatException excep)?}) → Future<InteractiveMessage?>
Marks a message as unread.
sendMediaMessage(MediaMessage mediaMessage, {required dynamic onSuccess(MediaMessage message)?, required dynamic onError(CometChatException excep)?}) → Future<MediaMessage?>
send a media message like photos, videos & files.
sendMessage(TextMessage message, {required dynamic onSuccess(TextMessage message)?, required dynamic onError(CometChatException excep)?}) → Future<TextMessage?>
To send a text message to a single user or group. returns the TextMessage with message id
sendTransientMessage(TransientMessage message, {required dynamic onSuccess()?, required dynamic onError(CometChatException excep)?}) → Future<void>
Transient messages are messages that are sent in real-time only
setDemoMetaInfo({required Map<String, String> jsonObject}) → Future<void>
Set demo metadata information.
setIntegrationSource(String source) → Future<void>
Sets the integration source for telemetry attribution.
setPlatformParams({required String platform, required String sdkVersion}) → Future<void>
Set platform parameters (platform name and SDK version).
setSource(String resource, String platform, String language) → Future<void>
Sets SDK source metadata.
startTyping({required String receiverUid, required String receiverType}) → Future<void>
method to inform the receiver that the logged in user has started typing.
subscribeToThread(int parentMessageId, {dynamic onSuccess(String result)?, dynamic onError(CometChatException excep)?}) → Future<String?>
Subscribes the logged-in user to the thread rooted at parentMessageId, so they are notified about replies that arrive in future — allowed even on a message with zero replies.
tagConversation(String conversationWith, String conversationType, List<String> tags, {required dynamic onSuccess(Conversation conversation)?, required dynamic onError(CometChatException excep)?}) → Future<Conversation?>
Tag a conversation
transferGroupOwnership({required String guid, required String uid, required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Transfers group ownership to another member.
unbanGroupMember({required String guid, required String uid, required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Unbans a member from a group.
unblockUser(List<String>? uids, {required dynamic onSuccess(Map<String, dynamic> map)?, required dynamic onError(CometChatException excep)?}) → Future<Map<String, dynamic>?>
Un-block a user from sending logged-in user any messages.
unpinConversation(String conversationWith, String conversationType, {dynamic onSuccess(Conversation conversation)?, dynamic onError(CometChatException excep)?}) → Future<Conversation?>
Unpin the logged-in user's conversation. Only a pin placed by the logged-in user can be removed — an app_system pin is rejected server-side. Returns the updated Conversation with the pin fields cleared to null.
unpinMessage(int messageId, {dynamic onSuccess(BaseMessage)?, dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Unpin a message from its conversation. Same permission model and idempotency as pinMessage; the returned message carries the pin fields cleared to null. Fans out MessageListener.onMessageUnpinned.
unsaveMessage(int messageId, {dynamic onSuccess(BaseMessage)?, dynamic onError(CometChatException excep)?}) → Future<BaseMessage?>
Unsave a message for the logged-in user. Same semantics as saveMessage; the returned message carries savedAt cleared to null. Fans out MessageListener.onMessageUnsaved.
unsubscribeFromThread(int parentMessageId, {dynamic onSuccess(String result)?, dynamic onError(CometChatException excep)?}) → Future<String?>
Unsubscribes the logged-in user from the thread rooted at parentMessageId.
updateCurrentUserDetails(User user, {required dynamic onSuccess(User user)?, required dynamic onError(CometChatException excep)?}) → Future<User?>
Updating a logged-in user is similar to updating a user
updateGroup({required Group group, required dynamic onSuccess(Group group)?, required dynamic onError(CometChatException excep)?}) → Future<Group?>
Updates group details.
updateGroupMemberScope({required String guid, required String uid, required String scope, required dynamic onSuccess(String result)?, required dynamic onError(CometChatException excep)?}) → Future<String?>
Updates a group member's scope (role).
updateUser(User user, String apiKey, {required dynamic onSuccess(User user)?, required dynamic onError(CometChatException excep)?}) → Future<User?>
Updating a user similar to creating a user should ideally be achieved at your backend using the Restful APIs