Push notification


Your flutter app should have a firebase cloud messaging integration to receive push notifications. Refer this doc to continue firebase cloud messaging integration

To Show Message Notifications in app foreground Refer this Message Notification's

Add runtime permissions for push notification#

From Android 13, To receive notification message, we need below permissions:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Updating fcm device token#

You need to update the fcm device token to the server, so that server can send push notificationns by using the updated fcm device token. if you want to update the fcm device token, you can utilise the below method.

FCM_TOKENStringfcm device token
flyCallbackFlyResponsecallback to observe the action status
Mirrorfly.updateFcmToken(firebaseToken: value, flyCallBack: (FlyResponse response) {

Handling the received chat fcm message#

Upon receiving a Firebase push notification in your Firebase Messaging service, you can utilize the following method to retrieve the notification content and subsequently create and display the notification.

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// Handle background messages
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp();
// We are checking the Platform Condition here, because we are handling the push notification in iOS via Notification Extension
if (Platform.isAndroid) {
//Handle the push notification as given below
var notificationData = remoteMessage.data;
Mirrorfly.handleReceivedMessage(notificationData: notificationData, flyCallBack: (FlyResponse response) {
if(response.isSuccess && response.hasData){
var data = sendMessageModelFromJson(response.data);
//Create and Display the Notification on your own
// In iOS, this will be handled within the plugin itself using the Notification Extension Service.

Get unread count without muted chat messages#

If you need a unread count excluding the muted chat messages, you can utilise the below method.

int? unReadMessageCount = await Mirrorfly.getUnreadMessageCountExceptMutedChat();