flutter_get_background_loc library
Accurate background location for Flutter.
Native (Kotlin/Swift) = location service only (raw fixes, GNSS metrics, IMU, OS mock flags). A headless background Dart isolate owns all filtering (null-safe gating + Kinematic Adaptive EKF), anti-spoofing heuristics and the single HTTP uploader with a persistent offline queue.
Classes
- AdaptiveKinematicEkf
- Portable Kinematic Adaptive Extended Kalman Filter (AKF).
- BackgroundDisclosureTexts
- Texts of the prominent background-location disclosure (English by default).
- BackgroundEntrypoint
-
A custom Dart entry point for the headless background engine. Needed for
anything that must be plugged into the background isolate (a
RoadSnapper): objects cannot cross isolates, so your own entry point builds them there. - BackgroundLocationDisclosure
- Prominent in-app disclosure that must be shown before the system location / background-location prompt (Google Play "User Data" policy).
- BackgroundRuntime
- Runs inside the headless background engine started by the native service (Android) / tracker (iOS). Receives RAW fixes from native, runs the LocationPipeline and publishes processed fixes + send results back to the UI isolate through native.
- BarometerConfig
- Barometer: relative altitude, floor-change estimate, lift/stairs cue.
- BarometerTracker
- Barometer based relative altitude, floor-change estimate and lift/stairs cue.
- DisclosureOutcome
- Result of BackgroundLocationDisclosure.requestWithDisclosure.
- DriveConfig
-
Drive mode: detects "the device is in a vehicle" and (optionally) switches the
EKF to a vehicle motion model. Pure Dart, no sensor of its own: it only uses
the filtered speed, the OS activity and the motion state that are already
there.
enabled: false= no detector,LocationFix.driveModestays false and nothing below applies. - DriveModeDetector
- Detects "the device is in a vehicle" with hysteresis.
- EkfStep
- Result of one AdaptiveKinematicEkf.process step.
- FilterConfig
- Configuration of the Dart filter engine (gating + adaptive EKF).
- FilterResult
- Outcome of processing one raw fix: the decision, the raw fix and, when emitted, the filtered output.
- FlutterGetBackgroundLoc
- UI-side entry point (singleton).
- FlutterGetBackgroundLocPlatform
-
Platform interface. Native implementations talk over
flutter_get_background_loc/methodsandflutter_get_background_loc/events. - GnssAssistanceRefresh
- Outcome of the optional assistance-data refresh that a warm-up may trigger (Android only).
- GnssWarmUpConfig
-
Optional automatic GNSS warm-up, part of
LocationConfig.warmUp. Off by default: nothing changes for existing apps unless autoWarmUpBeforeStart is true. - GnssWarmUpResult
- Result of FlutterGetBackgroundLoc.warmUpGnss.
- HealthStatus
- Snapshot of the background engine's health.
- HealthWarningTexts
-
Texts of HealthStatus.warnings. Replace them to localise your diagnostics screen.
{reason}/{name}are substituted where present. - Heartbeat
- Periodic status ping from the background isolate (default every 60 s).
- HeartbeatConfig
- Periodic status ping from the background isolate.
- IndoorConfig
- Indoor / high-rise behaviour: degraded output path, stationary anchor, safe EKF re-initialisation and the indoor-likelihood score.
- IndoorScorer
- "Probably indoors / inside a high-rise canyon" score per fix.
- IosConfig
- iOS-only options.
- IosUsageDescriptionReport
- Result of FlutterGetBackgroundLoc.checkIosUsageDescriptions.
- IosUsageDescriptions
-
iOS location-related
Info.plistkeys. The strings are owned by the HOST app (iOS shows them verbatim in the system prompt); the plugin cannot supply or change them. Copy the suggestions below into yourInfo.plist. - KeepAliveHttpPoster
- One long-lived HttpClient (HTTP keep-alive, connection reuse). Recreated after an I/O error.
- LocationConfig
- Full service configuration passed to FlutterGetBackgroundLoc.startService.
- LocationFilterEngine
- Cleaning pipeline (pure Dart, runs in the background isolate):
- LocationFix
- A single location fix with quality and anti-spoofing metadata.
- LocationPayloadBuilder
- Builds the JSON body POSTed to your server.
- LocationPermissionFlow
- Ready-made permission flow with every text and every dialog replaceable.
- LocationPermissionState
- Granular snapshot of everything that decides whether tracking can run. Build your own permission screens from it (FlutterGetBackgroundLoc.permissionState).
- LocationPipeline
- raw fix -> mock heuristics -> filter engine (gating + EKF) -> uploader.
- LocationUploader
- The ONLY uploader of the plugin (runs in the background isolate).
- MockConfig
- Multi-layer fake-GPS heuristics (evaluated in Dart).
- MockHeuristics
- Multi-layer anti-spoofing without QUERY_ALL_PACKAGES.
- MotionConfig
- Motion state machine (IMU + OS activity recognition).
- MotionTracker
- Motion state machine fed by the per-fix IMU window and by OS activity recognition events (Android Activity Transition and activity updates / iOS CMMotionActivity).
- MotionUpdate
- Motion state change published by the background isolate.
- NotificationAction
- One button below the notification text (Android shows at most 3).
- NotificationConfig
- The persistent notification of the Android foreground service.
- NotificationTemplate
- Placeholder engine for NotificationConfig.liveTextTemplate / NotificationConfig.liveTitleTemplate. The Android service uses the same rules natively; this Dart twin lets you preview a template in your UI.
- OemBackgroundHelper
- Standard battery exemption + themeable OEM autostart guide, written from scratch on the plugin's own MethodChannel (no third-party packages).
- OemGuideController
- Handed to a custom OemGuideBuilder to drive the guide.
- OemGuideDialog
-
Default guide dialog. Built on the widgets layer only, so it works with the legacy Material
library,
material_uiandcupertino_ui; text style and accent follow the calling context. - OemGuideOutcome
- Result of OemBackgroundHelper.ensureBackgroundPermission.
- OemGuideTexts
-
Customisable texts of the guide dialog.
{brand}and{app}are replaced in title and intro; steps overrides the built-in vendor-specific steps (also supports{app}). - OemSettingsResult
- Outcome of FlutterGetBackgroundLoc.openOemAutostartSettings.
- PayloadConfig
-
Which groups of fields end up in the uploaded JSON (and
buildPayload). Everything is on by default; switch a group off to keep the payload small or to avoid sending data you do not need.latitude,longitude,accuracyand the timestamps are always present. - PermissionFlowResult
- Result of LocationPermissionFlow.run.
- PermissionFlowTexts
-
All dialog texts of the flow. A
nullprompt skips that dialog (the permission itself is still requested). - PermissionPrompt
-
One dialog: title, body and the two buttons.
{app}is replaced in body. - PersistentQueue
- JSON-lines file queue that survives process death. Without a file path it is purely in-memory (tests / platforms without storage).
- PowerConfig
- Battery / wake-lock / batching policy (Android).
- RejectedFix
- A raw fix the filter rejected, with the reason.
- RestartConfig
- How the Android service restarts itself (Android 12+/14 restrictions).
- RoadSnapper
-
Pluggable map-matching ("snap to road") service. The package ships no
implementation and no network code for it;
example/contains an OSRM one. - RobustIndoorConfig
-
Optional indoor score and state detector (
IndoorConfig.robust). - SendConfig
- Where and how to send location fixes.
- SendResult
- Result of one HTTP send attempt (always produced by the background isolate).
- SequenceCounter
- Monotonically increasing sequence number that survives process death.
- SnapInput
- One position handed to a RoadSnapper.
- SnapPoint
- A position on the road network.
- Uuid
- RFC 4122 version-4 UUID without any package.
- VehicleModel
- Vehicle motion model options (drive mode only).
Enums
- FilterDecision
- Why a fix was accepted or dropped.
- FixQuality
- How trustworthy an emitted (filtered) fix is.
- GnssWarmUpFailure
- Why a GNSS warm-up did not reach its target. See GnssWarmUpResult.reason.
- IndoorState
-
Tri-state result of the optional robust indoor detector
(
IndoorConfig.robust). - LocationPermissionStatus
- Location permission level.
- LocationPriority
-
Fused-location priority used while the device is moving (
LocationConfig.priority). The still / anchored low-power switch (MotionConfig.balancedWhileStill) still applies on top. - MotionState
- Result of the stop-timeout state machine.
- NotificationActionType
- Behaviour of a notification action button.
- NotificationImportance
- Importance of the notification channel (Android 8+).
- NotificationTapAction
- What a tap on the notification body does.
- NotificationVisibility
- Lock-screen visibility of the notification.
- OemSettingsOutcome
- What FlutterGetBackgroundLoc.openOemAutostartSettings managed to open.
- OemVendor
- Phone vendors that ship an extra autostart / background manager.
- PermissionStep
- Steps of LocationPermissionFlow.
- ProviderMode
- Which native location source to use (Android).
- SendMode
- Who sends the location to your server.
- TrackingPreset
- Ready-made trade-offs between battery use and accuracy (0.10.0).
Properties
-
Process-wide keep-alive poster shared by uploaders.
final
Functions
-
bearingDegrees(
double lat1, double lng1, double lat2, double lng2) → double - Initial bearing from point 1 to point 2 in degrees (0..360, 0 = north).
-
defaultHttpPoster(
Uri url, Map< String, String> headers, String body, Duration timeout) → Future<int> - Default poster: shared keep-alive client.
-
defaultOemSteps(
OemVendor vendor) → List< String> - Built-in steps per vendor.
-
flutterGetBackgroundLocBackgroundMain(
) → Future< void> - Entry point of the headless background engine. Started natively by the Android LocationService / iOS LocationTracker – do not call it yourself.
-
haversineMeters(
double lat1, double lng1, double lat2, double lng2) → double - Great-circle distance between two WGS84 coordinates, in meters.
-
nextStillProbeIntervalMs(
{required MotionConfig config, required bool backoffActive, int currentMs = 0}) → int -
Next Android still-probe interval (ms). When backoff is inactive, this is
MotionConfig.stillProbeIntervalMs (possibly 0 = off). When active, the
interval doubles from
currentMsup to MotionConfig.stillProbeMaxIntervalMs. -
oneShotHttpPoster(
Uri url, Map< String, String> headers, String body, Duration timeout) → Future<int> -
One client per request (
SendConfig.keepAlive = false). -
runFlutterGetBackgroundLoc(
{RoadSnapper? roadSnapper}) → Future< void> -
Runs the background runtime. Call this from your own entry point (see
LocationConfig.backgroundEntrypoint) to plug custom objects - currently a RoadSnapper - into the background isolate.
Typedefs
-
BackgroundDisclosureBuilder
= Future<
bool> Function(BuildContext context, String title, String message) -
Fully custom disclosure UI. Return
truewhen the user agreed. -
FlushGuard
= Future<
void> Function(Future<void> body()) -
Wraps a flush so the OS keeps the process alive meanwhile (iOS
beginBackgroundTask/endBackgroundTask). -
HttpPoster
= Future<
int> Function(Uri url, Map<String, String> headers, String body, Duration timeout) - Performs one HTTP POST and returns the status code. Injectable for tests.
-
NetworkTypeProvider
= Future<
String> Function() -
wifi,ethernet,cellular,noneorunknown. - OemGuideBuilder = Widget Function(BuildContext context, OemGuideController guide)
- Builds a custom guide UI from an OemGuideController.
-
PermissionPromptBuilder
= Future<
bool> Function(BuildContext context, PermissionStep step, PermissionPrompt prompt) - Replaces the built-in dialog UI of every step with your own. Return true when the user agreed / wants to continue.