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).
- 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
-
Execute the
flutter packages getcommand. -
For iOS, navigate to the
iosdirectory in your project and execute:pod install. -
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
- 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:
- 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 {
}
- 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.