What this guide covers
- Adding the
cometchat_push_notificationsplugin and initializing it. - Platform wiring: Gradle/Firebase on Android, Podfile/capabilities/AppDelegate on iOS.
- Requesting permission and registering tokens (FCM on Android, APNs + VoIP on iOS) after login.
- Receiving pushes and letting the SDK render chat notifications and full-screen calls.
- Handling notification taps, incoming-call navigation, badge counts, and Android OEM permissions.
- Testing and troubleshooting.
The
cometchat_push_notifications plugin replaces the previous approach of copying the UI Kit sample’s lib/notifications stack and hand-wiring PNRegistry / CometChatPushRegistry, flutter_callkit_incoming, and native MainActivity / AppDelegate bridges. Token registration, foreground presentation, notification taps, badge management, and the full incoming-call experience (the Android lock-screen call activity and iOS CallKit) are handled inside the plugin.How it works
- Android (FCM): Firebase issues the registration token and delivers the CometChat payload as a data message. Your
firebase_messaginghandler forwardsmessage.datatohandlePushNotification, and the plugin shows the notification or full-screen call. - iOS (APNs + PushKit): Apple issues the APNs device token (chat alerts) and the VoIP token (calls). APNs alerts are shown by the system; VoIP pushes are presented through CallKit by the plugin.
- CometChat’s role: The providers you add in the dashboard bind your registered tokens to the logged-in user so CometChat can route pushes on your behalf.
- The plugin’s role:
cometchat_push_notificationsretrieves the tokens, registers them with CometChat, parses payloads, and drives the call UI. It builds oncometchat_sdk, which pub resolves for you.
Prerequisites
- The providers, Firebase project, and Apple/APNs credentials from Getting Started (this guide assumes those are done).
- Flutter 3.3.0+ / Dart 3.10.8+.
- Android: Kotlin 2.0+,
minSdkVersion 24,compileSdkVersion 36. - iOS: iOS 13.0+ (set the Podfile platform to 14.0 for VoIP/CallKit).
- A physical device — background delivery, full-screen calls, and VoIP pushes are unreliable on emulators/simulators.
Complete the Getting Started guide first — enable Push Notifications, add your providers (FCM for Android, APNs + APNs VoIP for iOS), and finish the Firebase/Apple setup. This guide covers only the Flutter app wiring.
1. Store your credentials
Keep the values from Getting Started somewhere your app can read them. Only the fields for the platforms you ship are needed:2. Add the plugin and configure the platform
Add the plugin topubspec.yaml. On Android also add Firebase Messaging (used to receive the FCM data messages):
cometchat_sdk is pulled in transitively. Run flutter pub get.
- Android
- iOS
With
google-services.json already in android/app/ (from Getting Started):- Apply the Google Services plugin and ensure Kotlin is 2.0+ in
android/settings.gradle.kts:
- Apply the plugins in
android/app/build.gradle.kts:
- Set
applicationIdto your package name and keepminSdk = 24or higher. Runflutterfire configureif you still needfirebase_options.dart.
You do not need to add notification, call, full-screen-intent, or lock-screen permissions to your
AndroidManifest.xml. The plugin declares everything it needs (including the lock-screen IncomingCallActivity and the Decline broadcast receiver), and Gradle merges them into your app automatically.3. Initialize the SDK
Initialize the plugin beforerunApp. On Android you also initialize Firebase and forward FCM messages to the plugin (including a background isolate handler).
- Android
- iOS
CometChatNotificationConfig also accepts:
Once the navigator is ready on your first screen after login, replay any cold-start call launch and route subsequent call taps:
navigatorKey to your MaterialApp.
Android: lock-screen call entrypoint
When a call arrives while the device is locked, the plugin launches a dedicated full-screen activity that runs a separate Dart entrypoint namedincomingCallMain. Define it in main.dart. It talks to the plugin’s native activity over the cometchat_locked_call method channel:
Adapt the accept path to launch your in-call screen. The channel methods (
getCallDetails, cancelNotification, finish, and the incoming reload) are the contract the plugin’s IncomingCallActivity exposes.4. Request permission and register tokens
Request permission early, and register tokens after your CometChat user logs in (registration binds the token to the session):- Android
- iOS
onTokenRefresh and automatically re-registers the new token with CometChat. Subscribe to CometChatPushNotifications.onTokenRefresh if you want to log it.
5. Notification taps and call events
Subscribe to the streams to navigate and coordinate call state (same on both platforms):setCallConnected(sessionId) (after media is established — critical for connecting calls from a terminated state), endCall(sessionId), endAllCalls() (on logout), and getActiveCallIds().
6. Android: OEM permissions for lock-screen calls
To reliably show a full-screen call over the lock screen — especially on Android 14+ and OEM skins like MIUI/Redmi/POCO — check and request the relevant permissions:7. Badge count
CometChat’s Enhanced Push Notification payload includes anunreadMessageCount field (the total unread across all conversations). Enable it once on the dashboard:
- Go to CometChat Dashboard → Notification Engine → Settings → Preferences → Push Notification Preferences.
- Enable the Unread Badge Count toggle.
- Android
- iOS
Set the badge from the payload (for example inside a foreground handler) using the plugin’s badge helper — no extra dependency needed:
WidgetsBindingObserver to your root widget and clear in initState and on AppLifecycleState.resumed.
8. Testing checklist
- Run on a physical device. Grant notification, microphone, and camera permissions when prompted (Android 13+ requires
POST_NOTIFICATIONS). - Send a message from another user:
- Foreground: no banner unless
showInAppNotifications: true(and you’re not already in that chat). - Background: a notification appears; tapping opens the right conversation via
onNotificationTap.
- Foreground: no banner unless
- Force-quit the app, send another message, tap the notification, and confirm it navigates to the conversation.
- Trigger an incoming CometChat call and confirm:
- The full-screen call UI (Android) / CallKit (iOS) shows the caller with Accept/Decline, even on the lock screen.
- Accepting starts the call session (via
onCallAccepted) and dismisses the notification when the call ends. - Declining rejects the call server-side (via your
onCallDeclined).
- Toggle Wi-Fi/cellular and reinstall to confirm token registration survives refreshes.
9. Troubleshooting
Resources
cometchat_push_notifications
The drop-in push & VoIP plugin on pub.dev.
SDK source
Source, changelog, and example app.