'How to keep Flutter app running on lock/sleep screen (geolocator and timer builder)?

I have a screen on my app that tracks the location (geolocator) and time with (timer_builder) when the user hits start button. When the screen locks/sleeps, it stops (or pause) tracking the location, but it should pause just when the user hits the stop button. Could anyone help me on this?

I believe there is difference between running the app on background vs on lock screen, because I just found topics about running the app on background with android_alarm_manager/background_fetch (on this case awaken app in the background about every 15 minutes would not work too). One solution would be prevent screen from going into sleep/lock mode, but then battery is problem. Any other solutions?

Thanks in advance!



Solution 1:[1]

I think background geolocation is a hard problem. However there is a project, flutter_background_geolocation. It works with debug mode. Unfortunately, in release mode, you need to purchase a license.

Solution 2:[2]

You can create background tasks with Flutter, see this article. Never tried it though.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akif
Solution 2 Szabolcs Szekelyi