flutter_branch_io_plugin 1.0.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

flutter-branch-io #

Flutter plugin implemented Branch IO's SDK to Flutter.

Supports both Android and iOS.

Implemented function:

  • Initialization and get Deep Link data to a subscribe-able stream on dart.
  • Create BUO and MetaData model
  • Generate new deeplink and get the link
  • List BUO on google search
  • Track content & evnt
  • Track user by id

HOW TO USE on iOS #

  • You need to call this code inside your application's initState
          if (Platform.isAndroid) FlutterBranchIoPlugin.setupBranchIO(); // will throw an exception if it fails
          FlutterBranchIoPlugin.listenToDeepLinkStream().listen((string) {
            print("DEEPLINK $string");
            // PROCESS DEEPLINK HERE
          });
          if (Platform.isAndroid) {
            FlutterAndroidLifecycle.listenToOnStartStream().listen((string) {
              print("ONSTART");
              FlutterBranchIoPlugin.setupBranchIO();
            });
          }
    

HOW TO USE on Android #

  • Import flutter_branch_io_plugin to your pubspec.yaml

  • Change these setups in your AndroidManifest.xml

    • Open your MainActivity and import com.anggach.flutterandroidlifecycle.FlutterAndroidLifecycleActivity

    • Change the MainActivity class to extend FlutterAndroidLifecycleActivity

    • Add this inside your AndroidManifest.xml (inside activity tag, after the Main and Launcher intent-filter)

            <!-- Branch URI scheme -->
            <intent-filter>
                <data android:scheme="YOURSCHEME" android:host="open"/>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
      
            <!-- Branch App Links -->
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="YOURHOST.test-app.link" />
            </intent-filter>
      

    Where YOURSCHEME is the Deep Link Scheme you setup at Branch.io dashboard, and YOURHOST is the Deep Link Host you setup at the dashboard

    • And add this inside application, (right after )

            <!-- Branch init -->
            <meta-data android:name="io.branch.sdk.BranchKey" android:value="YOURLIVEKEY" />
            <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="YOURTESTKEY" />
            <meta-data android:name="io.branch.sdk.TestMode" android:value="true" /> <!-- Set to true to use Branch_Test_Key -->
      
            <!-- Branch install referrer tracking -->
            <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER" />
                </intent-filter>
            </receiver>
      

      Where YOURLIVEKEY is your Branch.io live key, and YOURTESTKEY is your Branch.io test key.

    • Last, you need to call this code inside your application's initState

          if (Platform.isAndroid) FlutterBranchIoPlugin.setupBranchIO();  // will throw an exception if it fails
          FlutterBranchIoPlugin.listenToDeepLinkStream().listen((string) {
            print("DEEPLINK $string");
            // PROCESS DEEPLINK HERE
          });
          if (Platform.isAndroid) {
            FlutterAndroidLifecycle.listenToOnStartStream().listen((string) {
              print("ONSTART");
              FlutterBranchIoPlugin.setupBranchIO();
            });
          }
    

Functions #

  • To generate new deep link from flutter, you can use this (Support both Android & iOS) First, you need to subscribe to the generated link stream, which will produce the generated link after you created a link from a branch universal object

    FlutterBranchIoPlugin.listenToGeneratedLinkStream().listen((link) {
          print("GET LINK IN FLUTTER");
          print(link);
          setState(() {
            this.generatedLink = link;
          });
        });

Then, you can start generate new links based on any Branch Universal Object you pass, and you can also add some Link Properties inside (support Android & iOS)


    FlutterBranchIoPlugin.generateLink(
          FlutterBranchUniversalObject()
              .setCanonicalIdentifier("content/12345")
              .setTitle("My Content Title")
              .setContentDescription("My Content Description")
              .setContentImageUrl("https://lorempixel.com/400/400")
              .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
              .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC),
          lpChannel: "facebook",
          lpFeature: "sharing",
          lpCampaign: "content 123 launch",
          lpStage: "new user",
          lpControlParams: {
            "url": "http://www.google.com"
          }
        );
  • Track Content (Support Both Android & iOS) to track content, you can create a new branch universal object and some event identifier (String)
    FlutterBranchIoPlugin.trackContent( FlutterBranchUniversalObject()
            .setCanonicalIdentifier("content/12345")
            .setTitle("My Content Title")
            .setContentDescription("My Content Description")
            .setContentImageUrl("https://lorempixel.com/400/400")
            .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
            .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC), FlutterBranchStandardEvent.VIEW_ITEM);
  • Set User ID (support both Android & iOS) to set user id for current session, you can use
    FlutterBranchIoPlugin.setUserIdentity(USER_ID)
  • Clear User ID (support both Android & iOS) to clear user id for current session, you can use
    FlutterBranchIoPlugin.clearUserIdentity()
  • List Universal Object on Google Search (support Android only) to list an universal object on google search, you can use
    FlutterBranchIoPlugin.listOnGoogleSearch(
              FlutterBranchUniversalObject()
                  .setCanonicalIdentifier("content/12345")
                  .setTitle("My Content Title")
                  .setContentDescription("My Content Description")
                  .setContentImageUrl("https://lorempixel.com/400/400")
                  .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
                  .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC),
              lpChannel: "facebook",
              lpFeature: "sharing",
              lpCampaign: "content 123 launch",
              lpStage: "new user",
              lpControlParams: {
                "url": "http://www.google.com"
              }
            );

Version #

  • 0.0.1
    • Initial upload
  • 0.0.1+2
    • Add Swift dependencies and version
  • 0.0.1+3
    • Fix Branch data not received after user install
  • 0.0.1+4
    • Fix method not implemented errors on iOS
  • 0.0.1+5
    • Implement iOS swift side
  • 0.0.2
    • add iml to gitignore & adjust to Branch's new SDK functions including: remove arguments from isTestModeEnabled change enableLogging to enableDebugMode because deprecated
  • 0.0.2+1
    • Change README's obsolete instructions for Android
  • 0.0.2+2
    • Upgrade Kotlin version to 1.3.21
  • 0.0.3
    • Notify on Android if branch io can't be initialized
  • 1.0.0
    • Implement iOS scheme so we don't need to edit the AppDelegate file directly
  • 1.0.1
    • Fix errors in v1.0.0
    • Update flutter_android_lifecycle to v1.0.0
  • 1.0.1+1
    • Fix compilation error in new swift compiler

Contributor #

  • Angga Dwi Arifandi (anggadwiarifandi96@gmail.com)
  • Abdul Ghapur (gofur@oval.id)
  • Amond (amond@amond.net)

0.0.1 #

- Initial upload

0.0.1+2 #

- Add Swift dependencies and version

0.0.1+3 #

- Fix Branch data not received after user install

0.0.1+4 #

- Fix method not implemented errors on iOS

0.0.1+5 #

- Implement iOS swift side

0.0.2 #

- add iml to gitignore & adjust to Branch's new SDK functions including:
remove arguments from isTestModeEnabled
change enableLogging to enableDebugMode because deprecated

0.0.2+1 #

- Change README's obsolete instructions for Android

0.0.2+2 #

- Upgrade Kotlin version to 1.3.21

0.0.3 #

- Notify on Android if branch io can't be initialized

1.0.0 #

- Implement iOS scheme so we don't need to edit the `AppDelegate` file directly

1.0.1 #

- Fix errors in v1.0.0
- Update `flutter_android_lifecycle` to v1.0.0

1.0.1+1 #

- Fix compilation error in new swift compiler

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:io';

import 'package:flutter_android_lifecycle/flutter_android_lifecycle.dart';
import 'package:flutter_branch_io_plugin/flutter_branch_io_plugin.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _data = '-';
  String generatedLink = '-';
  String error = '-';

  @override
  void initState() {
    super.initState();

    try {
      setUpBranch();
    } catch (error) {
      setState(() {
        this.error = error.toString();
      });
      print("BRANCH ERROR ${error.toString()}");
    }
  }

  void setUpBranch() {
    if (Platform.isAndroid) {
      FlutterBranchIoPlugin.setupBranchIO();
    }

    FlutterBranchIoPlugin.listenToDeepLinkStream().listen((string) {
      print("DEEPLINK $string");
      setState(() {
        this._data = string;
      });
    });
    if (Platform.isAndroid) {
      FlutterAndroidLifecycle.listenToOnStartStream().listen((string) {
        print("ONSTART");
        FlutterBranchIoPlugin.setupBranchIO();
      });
    }

    FlutterBranchIoPlugin.listenToGeneratedLinkStream().listen((link) {
      print("GET LINK IN FLUTTER");
      print(link);
      setState(() {
        this.generatedLink = link;
      });
    });

    FlutterBranchIoPlugin.generateLink(
        FlutterBranchUniversalObject()
            .setCanonicalIdentifier("content/12345")
            .setTitle("My Content Title")
            .setContentDescription("My Content Description")
            .setContentImageUrl("https://lorempixel.com/400/400")
            .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
            .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC),
        lpChannel: "facebook",
        lpFeature: "sharing",
        lpCampaign: "content 123 launch",
        lpStage: "new user",
        lpControlParams: {
          "url": "http://www.google.com"
        }
    );

    FlutterBranchIoPlugin.trackContent( FlutterBranchUniversalObject()
        .setCanonicalIdentifier("content/12345")
        .setTitle("My Content Title")
        .setContentDescription("My Content Description")
        .setContentImageUrl("https://lorempixel.com/400/400")
        .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
        .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC), FlutterBranchStandardEvent.VIEW_ITEM);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Builder(builder: (context) {
          return Container(
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  child: Text(
                      "LATEST DATA BRANCH $_data"
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  child: Text(
                      "GENERATED LINK $generatedLink"
                  ),
                ),
                error.isEmpty ? Container() : Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  child: Text(
                      "ERROR: $error"
                  ),
                )
              ],
            ),
          );
        }),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_branch_io_plugin: ^1.0.1+1

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:flutter_branch_io_plugin/flutter_branch_io_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
83
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Apr 6, 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

Health suggestions

Format lib/flutter_branch_io_plugin.dart.

Run flutter format to format lib/flutter_branch_io_plugin.dart.

Format lib/src/models/branch_standard_event.dart.

Run flutter format to format lib/src/models/branch_standard_event.dart.

Format lib/src/models/branch_universal_object.dart.

Run flutter format to format lib/src/models/branch_universal_object.dart.

Format lib/src/models/content_meta_data.dart.

Run flutter format to format lib/src/models/content_meta_data.dart.

Format lib/src/models/link_properties.dart.

Run flutter format to format lib/src/models/link_properties.dart.

Maintenance suggestions

The package description is too short. (-17 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
flutter_android_lifecycle ^1.0.0 1.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