Heartbeat location update (fix #19)

This commit is contained in:
Anton Tananaev 2025-06-13 15:20:06 -07:00
parent d6fdbc0652
commit 32954b0a80

View file

@ -15,9 +15,20 @@ void main() async {
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
await Preferences.init(); await Preferences.init();
await bg.BackgroundGeolocation.ready(Preferences.geolocationConfig()); await bg.BackgroundGeolocation.ready(Preferences.geolocationConfig());
await bg.BackgroundGeolocation.registerHeadlessTask(headlessTask);
bg.BackgroundGeolocation.onHeartbeat((bg.HeartbeatEvent event) async {
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true);
});
runApp(const MainApp()); runApp(const MainApp());
} }
@pragma('vm:entry-point')
void headlessTask(bg.HeadlessEvent headlessEvent) async {
if (headlessEvent.name == bg.Event.HEARTBEAT) {
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true);
}
}
class MainApp extends StatefulWidget { class MainApp extends StatefulWidget {
const MainApp({super.key}); const MainApp({super.key});