flutter_background_geolocation
flutter_background_geolocation copied to clipboard
Getting redunt `onProviderChange` and `onConnectivityChange` callback event in headless
Your Environment
- Plugin version:
- Platform: iOS or Android
- OS version:
- Device manufacturer / model:
- Flutter info (
flutter doctor
): - Plugin config:
bg.BackgroundGeolocation.onProviderChange(onProviderChange);
bg.BackgroundGeolocation.onConnectivityChange(onConnectivityChange);
bg.Config(
...,
distanceFilter: isAndroid ? 0 : 200,
locationUpdateInterval: 600000,
fastestLocationUpdateInterval: 60000,
...
)
static void onProviderChange(bg.ProviderChangeEvent event) {
print(">>> event: $event")
}
static void onConnectivityChange(bg.ConnectivityChangeEvent event) {
print(">>> event: $event")
}
Expected Behavior
I expect callback to be present when they are mean't to be.
Actual Behavior
I am getting callback redunduntly and with exact same values.
Context
I need to log and process some process on the basis of the callback.
bg.BackgroundGeolocation.onProviderChange(onProviderChange); bg.BackgroundGeolocation.onConnectivityChange(onConnectivityChange);
You are not to use these in headless mode.
Your registered HeadlessTask in main.dart receives all headless events.
I have also registered them seperately also
bg.BackgroundGeolocation.registerHeadlessTask(
backgroundGeolocationHeadlessTask,
);
/// Receive events from BackgroundGeolocation in Headless state.
@pragma('vm:entry-point')
void backgroundGeolocationHeadlessTask(
bg.HeadlessEvent headlessEvent,
) {
switch (headlessEvent.name) {
case bg.Event.LOCATION:
LocationCallbackHandler.onLocation(headlessEvent.event);
break;
case bg.Event.CONNECTIVITYCHANGE:
LocationCallbackHandler.onConnectivityChange(headlessEvent.event);
break;
case bg.Event.PROVIDERCHANGE:
LocationCallbackHandler.onProviderChange(headlessEvent.event);
break;
case bg.Event.TERMINATE:
// something
break;
}
}
-
bg.BackgroundGeolocation.registerHeadlessTask
MUST be placed inmain.dart
- You do not use
BackgroundGeolocation.onXXX
inmain.dart
I suggest you have a look at the /example app in this repo.
- You do not use
BackgroundGeolocation.onXXX
inmain.dart
Couldn't follow you here. Could you kindly elaborate a bit further.
Look at the Example in the README.
Everything except .registerHeadlessTask
belongs INSIDE a Flutter Widget
.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.