Installation and initialization

To integrate AppMetrica Push SDK into Flutter, use the AppMetrica Push SDK for Flutter plugin:

  1. Install the AppMetrica Push SDK plugin in your project. From the root of the project, run the command:

    flutter pub add appmetrica_push_plugin
    

    After adding the plugin, you'll see a line with the following dependency in the pubspec.yaml file:

    dependencies:
        appmetrica_push_plugin: ^0.3.0
    
  2. Add appmetrica_plugin and appmetrica_push_plugin import:

    import 'package:appmetrica_plugin/appmetrica_plugin.dart';
    import 'package:appmetrica_push_plugin/appmetrica_push_plugin.dart';
    
  3. Initialize the AppMetrica SDK library using AppMetrica.activate and your API key:

    AppMetrica.activate(AppMetricaConfig("insert_your_api_key_here"));
    
  4. Initialize the AppMetrica Push SDK using AppMetricaPush.activate and your API key:

    AppMetricaPush.activate();
    
  5. To complete the integration of sending push notifications, use the documentation for each native platform:

    1. Set up the app for using Firebase. Get and add to AppMetrica a server key for using Firebase Cloud Messaging:

    2. Initialize Firebase transport using one of the following methods:

    Using Google Services Plugin

    1. Download the configuration file google-services.json and put it in the project module's directory (such as app).

    2. For the file to work correctly, enable the Google Services plugin in the project by adding the following lines to the Gradle file:

    project
    • build.gradle.kts

      buildscript {
            dependencies {
               classpath("com.google.gms:google-services:4.4.0")
            }
         }
      
    • build.gradle

      buildscript {
         dependencies {
            classpath "com.google.gms:google-services:4.4.0"
         }
      }
      
    application (module)
    • app/build.gradle.kts

      apply(plugin = "com.google.gms.google-services")
      
    • app/build.gradle

      apply plugin: "com.google.gms.google-services"
      
    Without using the plugin

    Make changes in the application element in the AndroidManifest.xml file:

    <meta-data android:name="ymp_firebase_default_app_id" android:value="APP_ID"/>
    <meta-data android:name="ymp_gcm_default_sender_id" android:value="number:SENDER_ID"/>
    <meta-data android:name="ymp_firebase_default_api_key" android:value="API_KEY"/>
    <meta-data android:name="ymp_firebase_default_project_id" android:value="PROJECT_ID"/>
    

    APP_ID — ID of the app in Firebase. You can find it in the Firebase console: go to the Project settings. In the Your application section copy the value of the application ID field.

    SENDER_ID — The unique ID of sender in Firebase. You can find it in the Firebase console: go to Project settings → Cloud Messaging and copy the value of the Sender ID field.

    API_KEY — App key in Firebase. You can find it in the current_key field of the google-services.json file. You can download the file in the Firebase console.

    PROJECT_ID — App ID in Firebase. You can find it in the project_id field of the google-services.json file. You can download the file in the Firebase console.

    Using with other Firebase projects

    Make changes in the application element in the AndroidManifest.xml file:

    <meta-data android:name="ymp_firebase_app_id" android:value="APP_ID"/>
    <meta-data android:name="ymp_gcm_sender_id" android:value="number:SENDER_ID"/>
    <meta-data android:name="ymp_firebase_api_key" android:value="API_KEY"/>
    <meta-data android:name="ymp_firebase_project_id" android:value="PROJECT_ID"/>
    

    APP_ID — ID of the app in Firebase. You can find it in the Firebase console: go to the Project settings. In the Your application section copy the value of the application ID field.

    SENDER_ID — The unique ID of sender in Firebase. You can find it in the Firebase console: go to Project settings → Cloud Messaging and copy the value of the Sender ID field.

    API_KEY — App key in Firebase. You can find it in the current_key field of the google-services.json file. You can download the file in the Firebase console.

    PROJECT_ID — App ID in Firebase. You can find it in the project_id field of the google-services.json file. You can download the file in the Firebase console.

    Alert

    You should initialize default Firebase project.

    3. If needed, configure silent push notifications or enable push tokens update.

    1. Add the SSL certificate to AppMetrica according to the instructions.

    2. Add Capability Push Notifications to your XCode project.

    3. If needed, enable push tokens update or configure uploading of attached files.

    4. Set up statistics collection.

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.

Contact support