Heartbeat location update (fix #19)
This commit is contained in:
parent
d6fdbc0652
commit
32954b0a80
1 changed files with 11 additions and 0 deletions
|
|
@ -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});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue