From 32954b0a80b70e43bdf6a94b5b9db34fa1635d9e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 13 Jun 2025 15:20:06 -0700 Subject: [PATCH] Heartbeat location update (fix #19) --- lib/main.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index c9fbfa8..f2090bc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,9 +15,20 @@ void main() async { FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; await Preferences.init(); 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()); } +@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 { const MainApp({super.key});