Skip to content

Data types

Every type below is a public class exported from the package root (lib/src/models.dart and lib/src/config.dart), so you can reference them directly in your own function signatures and widget state:

import 'package:bgeo_background_geolocation/bgeo_background_geolocation.dart' as bg;
void onFix(bg.Location location) { ... }

Fields declared non-nullable in the Dart source are always present on a successfully-parsed object; fields declared with a trailing ? are nullable/optional exactly as shown below — there is no separate “optional but never actually null” convention here, unlike TypeScript’s ?:. Two classes (Location, HeartbeatEvent, AuthorizationEvent) additionally expose a raw field: the untouched native payload as a permissive Map<String, dynamic> escape hatch for fields not otherwise typed.

Location & sensors

Location

The core location record. It’s the payload of onLocation and (when a fix exists) the location field of onMotionChange’s MotionChangeEvent and onHeartbeat’s HeartbeatEvent; the resolved value of getCurrentPosition(), the onLocation callback of watchPosition(), setOdometer()/resetOdometer(), and each element of sync()/getLocations()’s resolved list.

FieldTypeDescription
uuidStringUnique record id.
timestampStringISO-8601 UTC.
agedouble?Optional. Fix age in milliseconds at the time it was processed.
odometerdoubleCumulative odometer reading, metres.
coordsCoordsPosition/motion fields.
activityMotionActivityClassified motion activity at the time of the fix.
batteryBatteryDevice battery snapshot.
isMovingbool?Motion-state machine’s verdict at the time of this fix. null during a cold start’s unconfirmed-MOVING probing window (up to stopTimeout minutes after start()) — the engine emits is_moving: null there so a server falls back to speed rather than recording a phantom “started moving”. Treat null the same as false unless you care about the difference.
samplebool?Optional. true when this Location was resolved by getCurrentPosition() — either an existing fix served for a fresh-enough maximumAge, or the best (most accurate) of several fixes sampled internally — rather than delivered by the ambient tracking stream. Also true on the fix resolved by setOdometer()/resetOdometer() — that fix carries event: 'odometer' (see below) rather than coming from getCurrentPosition().
eventString?Optional. Tags why this record was produced when it isn’t a plain tracked fix. Observed values: 'motionchange' (the record captured just before entering the stationary state) and 'odometer' (the fix resolved by setOdometer()/resetOdometer()).
extrasMap<String, dynamic>?Optional passthrough — e.g. {'watch': true} on watchPosition() fixes. Config-level extras form the base of every record; per-call extras are layered on top.
rawMap<String, dynamic>The untouched native payload (permissive escape hatch), keyed by the original snake_case wire field names.

Field naming: unlike the RN/TS type (which keeps is_moving and some coords/battery fields snake_case to mirror the wire format), every typed Dart field here is camelCase (isMoving, altitudeAccuracy, isCharging, …) — the snake_case → camelCase mapping happens internally in each class’s fromMap constructor. Use raw if you need the original wire key names.

Coords

Nested inside Location.coords.

FieldTypeDescription
latitudedoubleDegrees.
longitudedoubleDegrees.
accuracydoubleHorizontal accuracy, metres.
altitudedouble?Optional. Metres above sea level.
altitudeAccuracydouble?Optional. Vertical accuracy, metres.
speeddouble?Optional. Metres/second.
speedAccuracydouble?Optional. Metres/second.
headingdouble?Optional. Degrees.
headingAccuracydouble?Optional. Degrees.
ellipsoidalAltitudedouble?Optional. Metres, WGS84 ellipsoidal (as opposed to altitude, which is mean-sea-level/geoid-based).

MotionActivity

Nested inside Location.activity. Its type values are also the vocabulary accepted by Config.triggerActivities (a CSV of these same strings) — see the activity type constants.

FieldTypeDescription
typeStringClassified activity — one of 'still', 'on_foot', 'walking', 'running', 'on_bicycle', 'in_vehicle', 'unknown'. Not a Dart enum; a plain string matching the activityType* constants.
confidenceintClassifier confidence for type.

Battery

Nested inside Location.battery.

FieldTypeDescription
leveldoubleBattery level, 0.0–1.0.
isChargingboolWhether the device is currently charging.

State

The tracker’s state snapshot: resolved by ready(), setConfig(), start(), stop(), and getState().

FieldTypeDescription
enabledboolWhether tracking is enabled (the persisted on/off intent).
isMovingbool?Optional. Current motion-state-machine verdict — same value as onMotionChange’s isMoving.
odometerdouble?Optional. Cumulative odometer reading, metres.
trackingModeint?Optional. Diagnostic.
connectedbool?Optional. Validated-internet connectivity — see ConnectivityChangeEvent.
geofenceCountint?Optional. Diagnostic counter.
rawMap<String, dynamic>The untouched native payload — every field the native engine returned, typed or not.

Only a handful of fields are typed: unlike the RN State type (which declares a larger superset of diagnostic fields such as lastRawFixAge, locationFailureCount, backgroundRearmCount, monitoredWakeRegions, …), the Dart State class only exposes the six fields above as typed properties. Any other native-reported field is still reachable — State implements operator [](String key) as a permissive index accessor, equivalent to reading raw[key] directly:

final state = await bg.BackgroundGeolocation.getState();
print(state.enabled);
print(state['lastRawFixAge']); // untyped, dynamic — same map as state.raw

Events

ProviderChangeEvent

Payload of onProviderChange and the resolved value of getProviderState() (same shape).

FieldTypeDescription
statusintOne of the authorizationStatus* constants — 3 is Always.
enabledboolWhether location services are on at all.
gpsboolGPS provider enabled.
networkboolNetwork provider enabled.
accuracyAuthorizationint?Optional, iOS only — accuracyAuthorizationFull/Reduced.

MotionChangeEvent

Payload of onMotionChange.

FieldTypeDescription
isMovingbooltrue on the moving transition, false on the stationary transition.
locationLocation?Optional — null on the very first motionchange of a tracking session, before any fix exists yet (the initial probe fires ahead of any location). Guard before dereferencing — see the Events reference for the same caveat.

HeartbeatEvent

Payload of onHeartbeat.

FieldTypeDescription
locationLocation?Optional. The last known location — null if no fix has been taken yet in the current session.
rawMap<String, dynamic>The untouched native payload.

GeofenceEvent

Payload of onGeofence.

FieldTypeDescription
identifierStringThe geofence’s identifier.
actionStringThe transition type — 'ENTER', 'EXIT', or 'DWELL'. Not a Dart enum.
locationLocationThe fix that triggered the transition. Required, not nullable.
extrasMap<String, dynamic>?Optional. The geofence’s own extras, echoed back.

GeofencesChangeEvent

Payload of onGeofencesChange — a delta of the OS-registered subset, not the full persisted set (see Geofence below and the Geofencing guide).

FieldTypeDescription
onList<Geofence>Geofences newly registered with the OS.
offList<Geofence>Geofences just unregistered.

HttpEvent

Payload of onHttp — fired once per completed location-sync HTTP request (log uploads do not emit this event; see the logging guide).

FieldTypeDescription
successbooltrue when status is 2xx.
statusintHTTP status code; 0 when the request never got a response (network error).
responseTextStringResponse body (or the error message when status is 0), truncated to 1024 characters.

CrashEvent

Payload of onCrash — an on-device collision confirmation. Armed only while moving, off by default; see Config.crashDetection.

FieldTypeDescription
timestampStringISO-8601 UTC, the confirmation moment.
peakGdoublePeak impact magnitude, in g.
impactDurationMsdoubleDuration of the impact signature, in ms.
preImpactSpeedMpsdoubleSpeed immediately before impact, in m/s.
locationLocation?Last known fix at confirmation time, or null if none was available.

DistractionEvent

Payload of onDistraction — an on-device distracted-driving episode. Armed only while moving, off by default; see Config.distractionDetection. This detects the phone being physically handled at driving speed — see Limitations for what it cannot see.

FieldTypeDescription
timestampStringISO-8601, the moment the episode closed.
startTimestampStringISO-8601, the episode start (same instant as the dds extras key below).
durationSecdoubleFinal episode duration in seconds (same value as the ddd extras key below).
causeString"h" handling-only (iOS), "s" handling + active screen (Android), "c" reserved for calls (not implemented).
locationLocation?Last known fix at close time, or null if none was available.

Distraction extras keys

While an episode is open (and never lost to a sparse fix stream), the engine stamps these keys into the extras of every uploaded Location — this is the wire contract a backend parses, independent of the distraction event above:

KeyTypeWhen presentMeaning
ddsnumberOn every uploaded fix while an episode is open, and on the closing fix.Unix seconds of the episode start. This value doubles as the episode id.
ddcstringAlongside dds.Cause: "h" handling-only (iOS), "s" handling + active screen (Android), "c" reserved for calls (not implemented).
dddnumberOnly on the first fix persisted after the episode ends.Final episode duration in seconds.

Rules for a backend consuming these keys:

  • Group fixes into an episode by equal dds value, not by adjacency in the fix stream — grouping by equal value survives gaps in delivery.
  • Episode duration is ddd from the closing fix. If the closing fix never arrives, fall back to the span of fixes carrying that dds — this is only a lower bound.
  • A short episode can produce no fixes “inside” it. If an episode is shorter than the interval between fixes, the next persisted fix simply carries dds, ddc and ddd together. Episodes are therefore never lost to a sparse fix stream.
  • A pending close wins a race with a new open. If a new episode opens before the previous episode’s close has been flushed to a fix, that fix carries the pending close’s dds/ddc/ddd triple in full; the newly opened episode’s dds/ddc pair is deferred to the next record. Grouping by equal dds (above) is unaffected either way.
  • Do not count episodes off the location stream. The closing triple (dds/ddc/ddd) rides every record built between the close and the first record that is actually persisted, so a sample: true one-shot and the location embedded inside another event can each carry it more than once. The uploaded-record contract is unaffected, but a consumer must count episodes from the distraction event instead — it fires once per episode in normal operation, but a rare disarm race can publish a second distraction event for the same episode (same dds/startTimestamp, different durationSec/ddd). A consumer that needs exact counts should dedupe by startTimestamp (equivalently dds).

ConnectivityChangeEvent

Payload of onConnectivityChange. Fired on validated-internet transitions (Android NET_CAPABILITY_VALIDATED / iOS NWPath.satisfied — a captive-portal Wi-Fi network reports false); a newly-registered listener also receives the current state as a synthetic first delivery — see the Events reference for the exact semantics.

FieldTypeDescription
connectedboolValidated-internet reachability.

AuthorizationEvent

Payload of onAuthorization — the outcome of a native, killed-app-safe token refresh configured via Config.authorization.

FieldTypeDescription
successboolWhether the refresh succeeded.
accessTokenString?Present on success — the new access token.
refreshTokenString?Present on success — the new refresh token.
statusint?Present on failure — the HTTP status the refresh request itself received.
rawMap<String, dynamic>The untouched native payload.

Authorization state

AuthState

Resolved value of getAuthState().

FieldTypeDescription
accessTokenString?Optional. The access token the native uploader currently holds.
refreshTokenString?Optional. The refresh token the native uploader currently holds.

Geofencing

Geofence

A persisted geofence definition — the shape accepted by addGeofence()/addGeofences() and returned by getGeofences() and the on/off lists of GeofencesChangeEvent. See the Geofencing guide for validation rules, proximity slicing, and DWELL semantics.

FieldTypeDescription
identifierStringUnique geofence id.
radiusdoubleMetres.
latitudedoubleDegrees.
longitudedoubleDegrees.
notifyOnEntrybool?Optional.
notifyOnExitbool?Optional.
notifyOnDwellbool?Optional.
loiteringDelayint?Optional. Milliseconds; required alongside notifyOnDwell for a DWELL transition.
extrasMap<String, dynamic>?Optional. Echoed back on the corresponding GeofenceEvent.

Positioning options

CurrentPositionOptions

Parameter of getCurrentPosition().

FieldTypeDescription
persistbool?Optional. Whether the resolved fix is added to the upload queue like a normal tracked point.
samplesint?Optional. Number of fixes to sample before returning the best (most accurate) one.
timeoutint?Optional. Seconds to wait before giving up.
maximumAgeint?Optional. Accept a cached fix up to this many milliseconds old instead of sampling a new one.
desiredAccuracyint?Optional. One of the desiredAccuracy* constants.
extrasMap<String, dynamic>?Optional. Merged into the returned location’s extras.

WatchPositionOptions

Parameter of watchPosition().

FieldTypeDescription
intervalint?Optional. Desired update interval, milliseconds.
desiredAccuracyint?Optional. One of the desiredAccuracy* constants.
persistbool?Optional. Whether fixes are added to the upload queue.
extrasMap<String, dynamic>?Optional. Merged into each returned location’s extras.

Logging

LogEntry

Element type of the list resolved by getLog(); written by BackgroundGeolocation.logger’s .error/.warn/.info/.debug/.verbose methods and the native engine itself. See the logging guide for retention and upload cadence.

FieldTypeDescription
tsStringISO-8601 UTC.
levelint1=ERROR, 2=WARN, 3=INFO, 4=DEBUG, 5=VERBOSE.
srcString'native' or 'js' (app-side Dart logger.* calls are tagged 'js' for RN/Transistor wire-format parity).
eventStringShort event tag.
messageString?Optional. Human-readable log line.
datadynamicOptional. JSON-decoded data attached to the line.

Headless

HeadlessEvent

Parameter of the HeadlessTask passed to registerHeadlessTask() — Android only.

typedef HeadlessTask = Future<void> Function(HeadlessEvent event);
FieldTypeDescription
nameStringThe event type — one of 'heartbeat', 'motionchange', 'geofence', 'providerchange', 'powersavechange', 'http', 'connectivitychange'. 'location' is deliberately not part of this set — see below.
paramsMap<String, dynamic>The rest of the event’s fields — e.g. a headless motionchange carries isMoving/location inside params, distinct from name.

No headless location: the Android engine never dispatches a location event headlessly. High-frequency location fixes are deliberately excluded to avoid spinning up a background isolate (and a wakelock) per fix while tracking, which would drain battery and risk ANRs/foreground-service-start restrictions; fixes taken while the Dart isolate isn’t running are still durably queued and uploaded natively. This mirrors the same note under onLocation on the Events reference. iOS never invokes a registered headless task at all — see registerHeadlessTask().

Configuration value classes

These two immutable classes are nested inside Config — pass instances of them as the notification and authorization named parameters.

Notification

Value of Config.notification Android — configures the persistent foreground-service notification required for background location. No-op on iOS, which has no equivalent concept.

FieldTypeDescription
titleString?Optional.
textString?Optional.
channelIdString?Optional. Android freezes channel importance per channelId — change the id to change importance.
channelNameString?Optional.
smallIconString?Optional. "drawable/name" or "mipmap/name".
colorString?Optional. "#RRGGBB".
priorityint?Optional. Transistor NOTIFICATION_PRIORITY_* scale: -2 MIN (default) .. 2 MAX.

Authorization

Value of Config.authorization — native token refresh so killed-app uploads survive an access-token expiry without a live Dart context. On a 401/403 the uploader exchanges refreshToken at refreshUrl (with refreshHeaders, body refreshPayload — the literal placeholder "{refreshToken}" is substituted; defaults to {refresh_token}). Outcomes surface via onAuthorization.

FieldTypeDescription
strategyString?Optional.
accessTokenString?Optional.
refreshTokenString?Optional.
refreshUrlString?Optional.
refreshPayloadMap<String, dynamic>?Optional. Body template; "{refreshToken}" is substituted with the current refresh token.
refreshHeadersMap<String, String>?Optional.

Subscriptions

Every on* listener method returns a plain Dart StreamSubscription<T> rather than a custom type — see the Events reference for the full model, including removeListeners() to tear down every listener at once.