• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


28 Mar, 2025

Updated at 18 May, 2025

How to fetch and save the device location periodically while the Flutter app is closed

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.