Installation
To add MoEngage Geofence SDK to your application, edit the application's pubspec.yaml file and add the below dependency to it:
dependencies:
moengage_geofence: $latestVersion
$latestVersion refers to the latest version of the plugin.
Post including the dependency, run flutter pub get command in the terminal to install the dependency.
After installing the plugin, use the following platform-specific configuration.
info |
Note This plugin is dependent on moengage_flutter plugin. Make sure you have installed the moengage_flutter plugin as well. Refer to the doc for the same. For location-triggered push to work, ensure your Application has:
|
Android Installation
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.moengage:geofence:$sdkVersion")
}
where $sdkVersion should be replaced by the latest version of the MoEngage Geofence SDK
iOS Installation
In the case of iOS, the native dependency is part of the Geofence flutter SDK itself, so there is no need to include any additional dependency for supporting Geofence.
Configuration
Start Geofence Monitoring
After integrating the geofence package call startGeofenceMonitoring() method to initiate the geofence module, this will fetch the geofences around the current location of the user. Please take a look at the iOS doc and Android doc for more information on Geofence. By default, the geofence feature is not enabled. You need to call the startGeofenceMonitoring() to receive location-triggered push messages.
import 'package:moengage_geofence/moengage_geofence.dart';
final MoEngageGeofence _moEngageGeofence = MoEngageGeofence(YOUR_APP_ID);
@override
void initState() {
super.initState();
initPlatformState();
///Starts Geofence Monitoring
_moEngageGeofence.startGeofenceMonitoring();
}
Stop Geofence Monitoring
If you want to stop the geofence monitoring or feature use the stopGeofenceMonitoring() API. This API will remove the existing geofences.
import 'package:moengage_geofence/moengage_geofence.dart';
final MoEngageGeofence _moEngageGeofence = MoEngageGeofence(YOUR_APP_ID);
@override
void initState() {
super.initState();
initPlatformState();
///Stops Geofence Monitoring
_moEngageGeofence.stopGeofenceMonitoring();
}