Recently, I came across a situation where I needed to save the user's current device location every hour. This needs to happen while the app is completely closed (not just minimized or running in the background).
So far, I haven't found any solution capable of achieving this with Flutter.
I even tried using the silent push concept from Firebase Messaging to trigger a message periodically, wake up the app, and save the location.
Example:
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
@pragma('vm:entry-point')
Future firebaseMessagingBackgroundHandler(RemoteMessage message) async {
try {
await getAndSaveLocation();
} catch (e) {
log(e.toString());
}
}
However, no Flutter package was able to fetch the location while the app was closed (both on Android and iOS).
I also tried using the WorkManager package but had no success.
Is there any solution for this scenario?
I tested the following packages to try to fetch the location:
location, geolocator, and background_location.