Skip to main content

Flutter Plugin Integration Guide

Flutter Plugin Integration

Add the bonree_flutter_plugin plugin in the pubspec.yaml file. Both local and remote dependencies are supported (choose one method).

  1. Add Dependency

Local Dependency:

Open pubspec.yaml, add bonree_flutter_plugin: under dependencies, and specify the local path, for example:

dependencies:
bonree_flutter_plugin:
path: ./bonree_flutter_plugin # Write the local path of the bonree_flutter_plugin package here

Remote Dependency:

Open pubspec.yaml, add bonree_flutter_plugin: under dependencies, as shown below:

dependencies:
bonree_flutter_plugin:

If necessary, add version constraints based on actual requirements, for example:

dependencies:
bonree_flutter_plugin: ^3.0.0
  1. Execute the flutter packages get command.

  2. For iOS, navigate to the ios directory in your project and execute: pod install.

  3. Import the package and replace runApp()

import 'package:bonree_flutter_plugin/bonree_flutter_plugin.dart';

void main() {
// runApp(MyApp());// Comment out the original runApp() method
Bonree().start(MyApp());
}

During runtime, the following log in Flutter indicates successful integration:

[INFO][BONREE]: bonree_flutter_plugin start success
  1. Flutter Boost Routing Framework Data Collection (Added in v3.5.0, skip this step if not using this framework)

To collect Flutter Boost routing framework data, BonreeFlutterBoostAwareMixin has been added to complete the collection by mixing in the global lifecycle observer.

Usage:

  1. Add the Flutter Boost global lifecycle implementation class in your application and mix in the corresponding mixin from the bonree plugin
import 'package:bonree_flutter_plugin/bonree_flutter_plugin.dart';
import 'package:flutter_boost/flutter_boost.dart';

class AppPageObserver extends GlobalPageVisibilityObserver with RUMFlutterBoostAwareMixin {

}
  1. Register the global listener in Flutter Boost
void main(List<String> args) {
PageVisibilityBinding.instance.addGlobalObserver(AppPageObserver()); // Boost framework requires this listener registration
Bonree().start(MyApp()); // Normal integration steps
}

BonreeSDK Integration

Refer to the integration sections in the Help Center: Android-Native and iOS-Native.