Flutter push notification setup for real time updates

Push Notification setup


  • Goto /android/build.gradle and add the following under buildscript -> dependencies classpath ''

  • Add the following at the bottom of the file: apply plugin: ''

It will look something like this:

buildscript {
    repositories {

    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // and
    dependencies {
      classpath ''
      classpath ''

apply plugin: ''
  • From login success callback, call ApplozicFlutter.registerForPushNotification();

  • Refer to the following FcmListenerService class and update the the one in your app. If you don't have one, you can create a new file.

package com.example.applozic_flutter;

import android.util.Log;
import com.applozic.mobicomkit.Applozic;
import com.applozic.mobicomkit.api.account.register.RegisterUserClientService;
import com.applozic.mobicomkit.api.account.user.MobiComUserPreference;
import com.applozic.mobicomkit.api.notification.MobiComPushReceiver;

public class FcmListenerService extends FirebaseMessagingService {
    private static final String TAG = "ApplozicFcmListener";

    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.i(TAG, "Message data:" + remoteMessage.getData());

        if (remoteMessage.getData().size() > 0) {
            if (MobiComPushReceiver.isMobiComPushNotification(remoteMessage.getData())) {
                Log.i(TAG, "Applozic notification processing...");
                MobiComPushReceiver.processMessageAsync(this, remoteMessage.getData());

    public void onNewToken(String registrationId) {

        Log.i(TAG, "Found Registration Id:" + registrationId);
        if (MobiComUserPreference.getInstance(this).isRegistered()) {
            try {
                new RegisterUserClientService(this).updatePushNotificationId(registrationId);
            } catch (Exception e) {
  • Add the FcmListenerService entry to your manifest.
<service android:name="<CLASS_PACKAGE>.FcmListenerService"
                <action android:name=""/>

For push notifications, you must have a Firebase account:

  • Sign-up to and create your application and generate push notification services file.

  • Download google-services.json from your Firebase Console and paste it to /android/app folder

  • Go to Applozic console, update the FCM Server Key from Firebase account to your Applozic account push notification section here.


  • Create APNs certificates and upload development and distributions certificates in applozic console you can refer this link here.

  • Do not forget to update capabilities.

  • Add the following file (ApplozicWrapper.swift) to your {APP_ROOT_FOLDER}/ios/Runner

  • Open {APP_ROOT_FOLDER}/ios/Runner/AppDelegate.swift file and add the functions that are present in the AppDelegate class below. If the file does not exists, create new one.

import UIKit
import Flutter

@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    UNUserNotificationCenter.current().delegate = self
            ApplozicWrapper.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            ApplozicWrapper.shared.userNotificationCenter(center, willPresent: notification, withCompletionHandler: { options in
        override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            ApplozicWrapper.shared.userNotificationCenter(center, didReceive: response, withCompletionHandler: {
        override func applicationWillTerminate(_ application: UIApplication) {
            ApplozicWrapper.shared.applicationWillTerminate(application: application)
        override func applicationWillEnterForeground(_ application: UIApplication) {
            UIApplication.shared.applicationIconBadgeNumber = 0
        override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
            print("DEVICE_TOKEN_DATA :: \(deviceToken.description)") // (SWIFT = 3) : TOKEN PARSING
            ApplozicWrapper.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)

Using flutter firebase_messaging plugin

If you are using firebase_messaging plugin in your app for push notifications, follow the below steps to make Applozic notifications work with the Firebase plugin:

  • Open and extends it with FlutterFirebaseMessagingService instead of FirebaseMessagingService.

  • In the file add:

import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
  • In AndroidManifest.xml file add or replace the below service inside tag:
        <action android:name=""/>
  • Add the below tools entry (If not already added) inside the tag of AndroidManifest.xml file as below: xmlns:tools=""
    For example (2nd line in the below snippet):
<manifest xmlns:android=""
  • Add the below entry in within the tag in your AndroidManifest.xml file:
<service   android:name="io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService"

What’s Next

Unread count

Did this page help you?