Default to moving state
This commit is contained in:
parent
1b11c708f8
commit
1b46a4e8b8
3 changed files with 14 additions and 8 deletions
|
|
@ -2,3 +2,5 @@ arb-dir: lib/l10n
|
||||||
template-arb-file: app_en.arb
|
template-arb-file: app_en.arb
|
||||||
output-localization-file: app_localizations.dart
|
output-localization-file: app_localizations.dart
|
||||||
preferred-supported-locales: [en]
|
preferred-supported-locales: [en]
|
||||||
|
synthetic-package: false
|
||||||
|
output-dir: lib/l10n
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,10 @@ class GeolocationService {
|
||||||
}
|
}
|
||||||
bg.BackgroundGeolocation.onEnabledChange(onEnabledChange);
|
bg.BackgroundGeolocation.onEnabledChange(onEnabledChange);
|
||||||
bg.BackgroundGeolocation.onMotionChange(onMotionChange);
|
bg.BackgroundGeolocation.onMotionChange(onMotionChange);
|
||||||
bg.BackgroundGeolocation.onLocation(onLocation);
|
|
||||||
bg.BackgroundGeolocation.onHeartbeat(onHeartbeat);
|
bg.BackgroundGeolocation.onHeartbeat(onHeartbeat);
|
||||||
|
bg.BackgroundGeolocation.onLocation(onLocation, (bg.LocationError error) {
|
||||||
|
developer.log('Location error', error: error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> onEnabledChange(bool enabled) async {
|
static Future<void> onEnabledChange(bool enabled) async {
|
||||||
|
|
@ -38,6 +40,10 @@ class GeolocationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> onHeartbeat(bg.HeartbeatEvent event) async {
|
||||||
|
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true, extras: {'heartbeat': true});
|
||||||
|
}
|
||||||
|
|
||||||
static Future<void> onLocation(bg.Location location) async {
|
static Future<void> onLocation(bg.Location location) async {
|
||||||
if (_shouldDelete(location)) {
|
if (_shouldDelete(location)) {
|
||||||
await bg.BackgroundGeolocation.destroyLocation(location.uuid);
|
await bg.BackgroundGeolocation.destroyLocation(location.uuid);
|
||||||
|
|
@ -51,10 +57,6 @@ class GeolocationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> onHeartbeat(bg.HeartbeatEvent event) async {
|
|
||||||
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true, extras: {'heartbeat': true});
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool _shouldDelete(bg.Location location) {
|
static bool _shouldDelete(bg.Location location) {
|
||||||
if (!location.isMoving) return false;
|
if (!location.isMoving) return false;
|
||||||
if (location.extras?.isNotEmpty == true) return false;
|
if (location.extras?.isNotEmpty == true) return false;
|
||||||
|
|
@ -113,11 +115,11 @@ void headlessTask(bg.HeadlessEvent headlessEvent) async {
|
||||||
case bg.Event.MOTIONCHANGE:
|
case bg.Event.MOTIONCHANGE:
|
||||||
await GeolocationService.onMotionChange(headlessEvent.event);
|
await GeolocationService.onMotionChange(headlessEvent.event);
|
||||||
break;
|
break;
|
||||||
case bg.Event.LOCATION:
|
|
||||||
await GeolocationService.onLocation(headlessEvent.event);
|
|
||||||
break;
|
|
||||||
case bg.Event.HEARTBEAT:
|
case bg.Event.HEARTBEAT:
|
||||||
await GeolocationService.onHeartbeat(headlessEvent.event);
|
await GeolocationService.onHeartbeat(headlessEvent.event);
|
||||||
break;
|
break;
|
||||||
|
case bg.Event.LOCATION:
|
||||||
|
await GeolocationService.onLocation(headlessEvent.event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class Preferences {
|
||||||
final fastestLocationUpdateInterval = (instance.getInt(fastestInterval) ?? 30) * 1000;
|
final fastestLocationUpdateInterval = (instance.getInt(fastestInterval) ?? 30) * 1000;
|
||||||
final heartbeatInterval = instance.getInt(heartbeat) ?? 0;
|
final heartbeatInterval = instance.getInt(heartbeat) ?? 0;
|
||||||
return bg.Config(
|
return bg.Config(
|
||||||
|
isMoving: true,
|
||||||
enableHeadless: true,
|
enableHeadless: true,
|
||||||
stopOnTerminate: false,
|
stopOnTerminate: false,
|
||||||
startOnBoot: true,
|
startOnBoot: true,
|
||||||
|
|
@ -102,6 +103,7 @@ class Preferences {
|
||||||
preventSuspend: heartbeatInterval > 0,
|
preventSuspend: heartbeatInterval > 0,
|
||||||
disableElasticity: true,
|
disableElasticity: true,
|
||||||
disableStopDetection: instance.getBool(stopDetection) == false,
|
disableStopDetection: instance.getBool(stopDetection) == false,
|
||||||
|
pausesLocationUpdatesAutomatically: Platform.isIOS ? !(isHighestAccuracy || instance.getBool(stopDetection) == false) : null,
|
||||||
fastestLocationUpdateInterval: isHighestAccuracy ? 0 : fastestLocationUpdateInterval,
|
fastestLocationUpdateInterval: isHighestAccuracy ? 0 : fastestLocationUpdateInterval,
|
||||||
backgroundPermissionRationale: bg.PermissionRationale(
|
backgroundPermissionRationale: bg.PermissionRationale(
|
||||||
title: 'Allow {applicationName} to access this device\'s location in the background',
|
title: 'Allow {applicationName} to access this device\'s location in the background',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue