moengage_flutter 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

MoEngage Flutter Plugin #

Flutter Plugin for MoEngage Platform

SDK Installation #

To add the MoEngage Flutter SDK to your application, edit your application's pubspec.yaml file and add the below dependency to it:

dependencies:
 moengage_flutter: 1.0.0

Run flutter packages get to install the SDK.

Android Installation #

Download

Once you install the Flutter Plugin add MoEngage's native Android SDK dependency to the Android project of your application. Navigate to android --> app --> build.gradle. Add the MoEngage Android SDK's dependency in the dependencies block

  dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.0.1'
    implementation "com.moengage:moe-android-sdk:$sdkVersion"
}

where $sdkVersion should be replaced by the latest version of the MoEngage SDK.

SDK Initialization #

Android SDK Initialization #

Get APP ID from the Settings Page on the MoEngage dashboard and initialize the MoEngage SDK in the Application class's onCreate()

// this is the instance of the application class and "XXXXXXXXXXX" is the APP ID from the dashboard.
val moEngage =
        new MoEngage.Builder(this, "XXXXXXXXXXX")
        .build()
MoEInitializer.initialize(builder.build())

Refer to the API reference doc for a detailed list of possible configurations.

Note:
All the configuration should be added to the builder before calling initialize. If you are calling initialize at multiple places please ensure that all the required flags and configuration are set each time you initialize to maintain consistency in behavior.

iOS SDK Initialization #

Make sure to run flutter build command to make sure all the CocoaPods dependencies are added to your project. (i.e, MoEngage-iOS-SDK and moengage_flutter)

To initialize the iOS Application with the MoEngage App ID from Settings in Dashboard. In your project, go to AppDelegate file and call the initialize method of MOFlutterInitializer instance in applicationdidFinishLaunchingWithOptions() method as shown below:

  MOFlutterInitializer.sharedInstance.initializeWithAppID("Your App ID", withLaunchOptions: launchOptions)

Refer to the Documentation for complete integration guide.

1.1.0 (10-02-2020) #

  • Add Dart APIs for passing FCM Push Token and FCM Push Payload from Android Platform.

1.0.1 (17-12-2019) #

  • Sample Updated
  • ReadMe Updated
  • Improved logging

1.0.0 (16-12-2019) #

  • Initial Release

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:moengage_flutter/moengage_flutter.dart';
import 'package:moengage_flutter/geo_location.dart';
import 'package:moengage_flutter/properties.dart';
import 'package:moengage_flutter/gender.dart';
import 'package:moengage_flutter/app_status.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final MoEngageFlutter _moengagePlugin = MoEngageFlutter();

  void _onPushClick(Map<String, dynamic> message) {
    print("This is a push click callback from native to flutter. Payload " +
        message.toString());
  }

  void _onInAppClick(Map<String, dynamic> message) {
    print("This is a inapp click callback from native to flutter. Payload " +
        message.toString());
  }

  void _onInAppShown(Map<String, dynamic> message) {
    print("This is a callback on inapp shown from native to flutter. Payload " +
        message.toString());
  }

  @override
  void initState() {
    super.initState();
    initPlatformState();
    _moengagePlugin.initialise();
    _moengagePlugin.setUpPushCallbacks(_onPushClick);
    _moengagePlugin.setUpInAppCallbacks(
        onInAppClick: _onInAppClick, onInAppShown: _onInAppShown);
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: new ListView(
            children: ListTile.divideTiles(context: context, tiles: [
              new ListTile(
                  title: new Text("Track Event with Attributes"),
                  onTap: () {
                    var details = MoEProperties();
                    details
                        .addInteger("temp", 1)
                        .addBoolean("temp1", true)
                        .addDouble("temp2", 12.30)
                        .setNonInteractiveEvent()
                        .addLocation(
                            "location1", new MoEGeoLocation(12.1, 77.18))
                        .addLocation(
                            "location2", new MoEGeoLocation(12.2, 77.28))
                        .addLocation(
                            "location3", new MoEGeoLocation(12.3, 77.38))
                        .addISODateTime("dateTime1", "2019-12-02T08:26:21.170Z")
                        .addISODateTime(
                            "dateTime2", "2019-12-06T08:26:21.170Z");
                    _moengagePlugin.trackEvent('testEvent', details);
                  }),
              new ListTile(
                  title: new Text("Set Unique Id"),
                  onTap: () {
                    _moengagePlugin.setUniqueId('mobiledevs@moengage.com');
                  }),
              new ListTile(
                  title: new Text("Set UserName"),
                  onTap: () {
                    _moengagePlugin.setUserName('MoEngage Inc');
                  }),
              new ListTile(
                  title: new Text("Set FirstName"),
                  onTap: () {
                    _moengagePlugin.setFirstName("MoEngage");
                  }),
              new ListTile(
                  title: new Text("Set LastName"),
                  onTap: () {
                    _moengagePlugin.setLastName("Inc");
                  }),
              new ListTile(
                  title: new Text("Set Email-Id"),
                  onTap: () {
                    _moengagePlugin.setEmail("mobiledevs@moengage.com");
                  }),
              new ListTile(
                  title: new Text("Set Phone Number"),
                  onTap: () {
                    _moengagePlugin.setPhoneNumber("1234567890");
                  }),
              new ListTile(
                  title: new Text("Set Gender"),
                  onTap: () {
                    _moengagePlugin.setGender(MoEGender.male);
                  }),
              new ListTile(
                  title: new Text("Set Location"),
                  onTap: () {
                    _moengagePlugin.setLocation(new MoEGeoLocation(23.1, 21.2));
                  }),
              new ListTile(
                  title: Text("App Status - Install"),
                  onTap: () {
                    _moengagePlugin.setAppStatus(MoEAppStatus.install);
                  }),
              new ListTile(
                  title: Text("App Status - Update"),
                  onTap: () {
                    _moengagePlugin.setAppStatus(MoEAppStatus.update);
                  }),
              new ListTile(
                  title: Text("iOS -- Register For Push"),
                  onTap: () {
                    _moengagePlugin.registerForPushNotification();
                  }),
              new ListTile(
                  title: Text("Show InApp"),
                  onTap: () {
                    _moengagePlugin.showInApp();
                  }),
              new ListTile(
                  title: Text("Only Event"),
                  onTap: () {
                    _moengagePlugin.trackEvent("testEvent", null);
                  }),
              new ListTile(
                  title: Text("Set Birthday"),
                  onTap: () {
                    _moengagePlugin.setBirthDate("2019-12-02T08:26:21.170Z");
                  }),
              new ListTile(
                title: Text("Set Alias"),
                onTap: () {
                  _moengagePlugin.setAlias('testUser@moengage.com');
                },
              ),
              new ListTile(
                title: Text("Set Time"),
                onTap: () {
                  _moengagePlugin.setIsoDate(
                      "timeStamp", "2019-12-02T08:26:21.170Z");
                },
              ),
              new ListTile(
                  title: Text("Push Token"),
                  onTap: () {
                    _moengagePlugin.passPushToken("dummyToken");
                  }),
              new ListTile(
                  title: Text("Push Payload"),
                  onTap: () {
                    var pushPayload = Map<String, String>();
                    pushPayload.putIfAbsent("push_from", () => "moengage");
                    pushPayload.putIfAbsent("gcm_title", () => "Title");
                    pushPayload.putIfAbsent(
                        "gcm_notificationType", () => "normal notification");
                    pushPayload.putIfAbsent("gcm_alert", () => "Message");
                    pushPayload.putIfAbsent("gcm_campaign_id", () => "123456");
                    pushPayload.putIfAbsent("gcm_activityName",
                        () => "com.moe.pushlibrary.activities.MoEActivity");
                    _moengagePlugin.passPushPayload(pushPayload);
                  }),
              new ListTile(
                title: Text("Logout"),
                onTap: () {
                  _moengagePlugin.logout();
                },
              ),
            ]).toList(),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  moengage_flutter: ^1.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:moengage_flutter/moengage_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test