transistorsoft / transistorsoft/flutter_background_geolocation
events such as onGeofence, onLocation, and onMotionChange not getting triggered sometimes in alive state and never triggers in killed state in both Android and iOS.
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 732
- Forks
- 285
- PR merge metrics
- No merged PRs in 30d
Description
Your Environment
-
Plugin version: 4.11.1
-
Platform: iOS and Android
-
OS version: Androi(12) adn iOS(16.4)
-
Device manufacturer / model: Android (Redmi Note 10 (13.0.4)) and iOS (iPhone XR)
-
Flutter info (
flutter doctor): -
Plugin config:
// 1. Listen to events (See docs for all 13 available events).
bg.BackgroundGeolocation.onMotionChange(_onMotionChange);
bg.BackgroundGeolocation.onActivityChange(_onActivityChange);
bg.BackgroundGeolocation.onConnectivityChange(_onConnectivityChange);
bg.BackgroundGeolocation.onGeofence(_onGeofence);
bg.TransistorAuthorizationToken token =
await bg.TransistorAuthorizationToken.findOrCreate(
orgname, username, 'https://tracker.transistorsoft.com');
// 2. Configure the plugin
bg.BackgroundGeolocation.ready(bg.Config(
//schedule: ,
reset:
false, // <-- lets the Settings screen drive the config rather than re-applying each boot.
// Convenience option to automatically configure the SDK to post to Transistor Demo server.
transistorAuthorizationToken: token,
// Logging & Debug
debug: false,
logLevel: bg.Config.LOG_LEVEL_VERBOSE,
// Geolocation options
desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
distanceFilter: 10.0,
// Activity recognition options
stopTimeout: 5,
backgroundPermissionRationale: bg.PermissionRationale(
title:
"Allow {applicationName} to access this device's location even when the app is closed or not in use.",
message:
"This app collects location data to enable recording your trips to work and calculate distance-travelled.",
positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
negativeAction: 'Cancel'),
// HTTP & Persistence
autoSync: true,
// Application options
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
heartbeatInterval: 60))
.then((bg.State state) async {
print('[ready] ${state.toMap()}');
print('[didDeviceReboot] ${state.didDeviceReboot}');
_enabled = state.enabled;
_isMoving = state.isMoving ??= false;
bg.BackgroundGeolocation.start();
bg.BackgroundGeolocation.changePace(_isMoving);
bg.BackgroundGeolocation.startGeofences();
if (state.schedule != null && state.schedule!.isNotEmpty) {
bg.BackgroundGeolocation.startSchedule();
}
CommonFunction.giveSuccessToast("Start Geofence Tracking");
}).catchError((error) {
print('[ready] ERROR: $error');
});
Expected Behavior
The _onGeofence event should trigger whenever user enter or exit the geofence radius in both app alive and killed state
Actual Behavior
- If user enter or exit the geofence radius, sometimes the _onGeofence event is triggering but sometimes it is not, the way we have tested is through walking
- The events are never triggered when the app is killed,
we have added the backgroundGeolocationHeadlessTask and registered that in main.dart and also configured _configureBackgroundFetch()
void _configureBackgroundFetch() async {
BackgroundFetch.configure(
BackgroundFetchConfig(
minimumFetchInterval: 15,
startOnBoot: true,
stopOnTerminate: false,
enableHeadless: true,
requiresStorageNotLow: false,
requiresBatteryNotLow: false,
requiresCharging: false,
requiresDeviceIdle: false,
requiredNetworkType: NetworkType.NONE), (String taskId) async {
print("[BackgroundFetch] received event $taskId");
if (taskId == 'flutter_background_fetch') {
try {
// Fetch current position
var location = await bg.BackgroundGeolocation.getCurrentPosition(
samples: 1,
extras: {"event": "background-fetch", "headless": false});
print("[location] $location");
} catch (error) {
print("[location] ERROR: $error");
}
}
// Test scheduling a custom-task in fetch event.
BackgroundFetch.scheduleTask(TaskConfig(
taskId: "com.transistorsoft.customtask",
delay: 5000,
periodic: false,
forceAlarmManager: true,
stopOnTerminate: false,
enableHeadless: true));
BackgroundFetch.finish(taskId);
});
CommonFunction.giveSuccessToast("Background fetch configured");
}
Steps to Reproduce
- Add desired geofences
- Start Walking
- walk by entering and exiting from the given geofence radius
- The event should trigger both in live and killed state of the app
Context
We are trying to auto logging in user based on the given geofence radius, if user enter the given geofence radius we will be sending local notification that "you have entered the location" and we will do an api call to add timelog in Database, if user exit, as same as enter.
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the event registrations and ready configuration in the reported Dart entry point, then inspect backgroundGeolocationHeadlessTask and _configureBackgroundFetch() in main.dart. Reproduce the enter/exit steps on Android 12/13 and iOS 16.4 while collecting the plugin logs requested in the template. Done means onGeofence is observed for enter and exit in alive and killed states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, flutter, ios
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100