Getting started (Android)

Add app in your firebase console. You can follow this guide Firebase Setup. Just download google-services.json.

Copy google-services.json into your root of app assets directory this is important step.

Now in order to enable Firebase services in our Android app, add the google-services plugin to our Gradle files.

First in our root-level (project-level) Gradle file (android/build.gradle), add rules to include the Google Services Gradle plugin.

Check if the following configurations are available or not:

    buildscript {
        ext.kotlin_version = '1.5.21'
        repositories {
            google()
            mavenCentral()
        }

        dependencies {
            classpath 'com.android.tools.build:gradle:4.1.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.10'
        }
    }

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }

    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

Now in our module (app-level) Gradle file (android/app/build.gradle), apply the Google Services Gradle plugin. For that, add the piece of code highlighted in the following code snippet to the ./android/app/build.gradle file of our project:

    apply plugin: 'com.google.gms.google-services'

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation platform('com.google.firebase:firebase-bom:29.0.0')
        implementation 'com.google.firebase:firebase-analytics-ktx'
    }

Now, run the following command so that some automatic configurations can be made:

    flutter pub get

Using Feedify you can also send http/ https URLs into the notifications hence to support them android has now introduced to add query parameters into your AndroidManifest.xml like below:

    <queries>
            <!-- If your app opens https URLs -->
            <intent>
                <action android:name="android.intent.action.VIEW" />
                <data android:scheme="https" />
            </intent>
            <intent>
                <action android:name="android.intent.action.VIEW" />
                <data android:scheme="http" />
            </intent>
        </queries>

You can read more at android developer's site

Usage (common for Android and iOS)

    void main() async {
      initFeedSDK();
      runApp(const MyApp());
    }

    void initFeedSDK() async {
      WidgetsFlutterBinding.ensureInitialized();
      var sdk = FeedSDK.getInstance(
          feedifyKey: 'key',
          feedifyDomain: 'domain',
          feedifyUser: 'userKey');
      // mandatory to set the notification icon, else notification alert will not show
      FeedSDK.setNotificationIcon('resource://drawable/ic_notification');
      // If FeedSDK.startScreen is set then all the notification payload data is passed to the root widget of your app
      FeedSDK.startScreen = 'test';
      Logs.setEnabled(true);
      await sdk.init(
          appName: 'your app name',
          projectId: 'firebase project Id',
          firebaseCurrentApiKey: 'firebase api key',
          firebaseMobileSdkAppId: 'firebase mobile app sdk id',
          firebaseStorageBucket: 'firebase storage key url',
          firebaseUrl: '',
          firebaseProjectNumber: 'firebase project number');
    }
  • Note: All the above information can be found in google-services.json and info.plist file that has been already downloaded from Google firebase console.

If you have set FeedSDK.startScreen and want to override the SDK's default behaviour by receiving all the data payload to the main app class, then you need to do add the below package into your pubspec.yaml file (don't forget to call - 'flutter pub get')

    get: ^4.3.7

then add the GetMaterialApp widget as below sample:

    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);

      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return GetMaterialApp(
          onGenerateRoute: (settings) {
            if (settings.name == FeedSDK.startScreen) {
              final args = settings.arguments;
              Logs.d('onGenerateRoute $args');
            }
          },
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }

You can read the data based on the keys available inside Constants class.

How to read the notification data in your app?

When FeedSDK.startScreen = '#any text' is set, then the data is passed to the root widget of your app, then you can read the data as below, which can be used for deeplinking or navigating through your app based on the notification data:

  class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);

      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return GetMaterialApp(
          onGenerateRoute: (settings) {
            if (settings.name == FeedSDK.startScreen) {
              final args = settings.arguments as List<Map<String, String>>;
              var icon = args[0][Constants.icon];
              var title = args[0][Constants.title];
              var body = args[0][Constants.body];
              var type = args[0][Constants.type];
              Logs.d(icon! + title! + body! + type!);
            }
          },
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }

Getting started (iOS)

Integrating the Cloud Messaging plugin on iOS & macOS devices requires additional setup before your devices receive messages. There are also a number of prerequisites which are required to be able to enable messaging:

For configuring FCM on iOS devices, follow the steps mentioned in here

The most important part in order to make this library work is

Libraries

const
feedify
logs