Skip to main content
Prerequisites: Flutter SDK 1.2+, Android API Level 21+, iOS 11+ Credentials: App ID, Region, Auth Key (dev) or Auth Token (prod) from CometChat Dashboard

Prerequisites

Get your credentials from the CometChat Dashboard:
  1. Create a new app
  2. Head over to the API & Auth Keys section and note the Auth Key, App ID & Region
Auth Key is for development/testing only. In production, generate Auth Tokens on your server using the REST API. Never expose Auth Keys in production client code.

Installation

Add the following dependency to your pubspec.yaml file and run pub get:

iOS Setup

  1. Add the following to your Podfile inside the iOS section of your app:
Apple Silicon (M1/M2/M3) users: Excluding arm64 from the simulator build prevents the app from running natively on Apple Silicon Macs. If you are developing on an Apple Silicon Mac, consider excluding only i386 instead of arm64 i386 to enable native simulator builds.
  1. Change the deployment target to 11 or higher.
  2. Navigate to your iOS folder in terminal and run pod install. For Apple Silicon systems, use a Rosetta terminal.
  3. Set Enabled Bitcode to NO in the Build Settings of your Xcode project.

Import the SDK

Initialization

The init() method initializes the SDK and must be called before any other CometChat method. Call it once at app startup, typically in your root widget’s initState() or main() function.
Replace APP_ID and APP_REGION with your credentials from the Dashboard.
CometChat.init() must be called before any other SDK method. Calling login(), sendMessage(), or registering listeners before init() will fail.

Parameters

AppSettings Options

Presence Subscription

Choose how to subscribe to user presence (online/offline status):
See User Presence for more details.
On Success — A String message confirming SDK initialization:

WebSocket Connection

By default, the SDK manages WebSocket connections automatically. To manage them manually:
See Connection Behaviour for manual control.

Next Steps

Authentication

Log in users with Auth Key or Auth Token

Send Messages

Send your first message