Skip to content

State

class State

Read-only snapshot of the SDK's current runtime state.

final state = await BackgroundGeolocation.state;
print('[state] enabled: ${state.enabled}, trackingMode: ${state.trackingMode}');
Properties
Property Type Description
enabled Boolean Whether the SDK is currently tracking.
isMoving Boolean Whether the device is currently in motion.
trackingMode TrackingMode Current tracking mode: LOCATION or GEOFENCE.
odometer Double Distance travelled in metres since last reset.
schedulerEnabled Boolean Whether the scheduler is currently active.
didDeviceReboot Boolean Whether the device rebooted since the SDK was last running.

Members

activity

ActivityConfigget activity

Motion recognition, stop-detection triggers, and motion-trigger delay. See ActivityConfig.

app

AppConfigget app

App lifecycle — background operation, boot behaviour, headless mode, and foreground notification. See AppConfig.

didDeviceReboot

bool didDeviceReboot

true when the app was launched after a device reboot.

didLaunchInBackground

bool didLaunchInBackground

iOS only true when the app was relaunched in the background by the OS — for example, due to a background fetch, geofence exit, or stationary geofence transition. On Android, background launch is handled by the Headless Task mechanism — this property does not apply.

enabled

bool enabled

true when the SDK is actively tracking — i.e. BackgroundGeolocation.start or BackgroundGeolocation.startGeofences has been called and not yet stopped.

geolocation

GeoConfigget geolocation

Accuracy, sampling, elasticity, stop-detection, permissions, and geofencing. See GeoConfig.

http

HttpConfigget http

Upload URL, HTTP method, sync cadence, batching, headers, and params. See HttpConfig.

isFirstBoot

bool isFirstBoot

true on the very first launch after the app is installed.

isMoving

bool? isMoving

true when the SDK is in the moving state (location services active); false when stationary.

// Toggle the SDK's motion state from stationary to moving.
BackgroundGeolocation.onMotionChange((MotionChangeEvent event) {
  print('[onMotionChange] isMoving? ${event.isMoving}');
});

await BackgroundGeolocation.changePace(true);
// State.isMoving is now true.

logger

LoggerConfigget logger

Debug logging, log level, and log retention. See LoggerConfig.

odometer

double odometer

Accumulated distance traveled since the last odometer reset, in meters.

See also - odometerError - BackgroundGeolocation.setOdometer - BackgroundGeolocation.getOdometer

persistence

PersistenceConfigget persistence

SQLite storage, TTL, record limits, and custom extras. See PersistenceConfig.

schedulerEnabled

bool schedulerEnabled

true when a AppConfig.schedule is configured and BackgroundGeolocation.startSchedule has been called. BackgroundGeolocation.stopSchedule sets this to false.

trackingMode

int trackingMode

Current tracking mode.

Value Mode Description
0 Geofences Geofence monitoring only — no active location tracking.
1 Location Location tracking and geofence monitoring.
await BackgroundGeolocation.start();
final state = await BackgroundGeolocation.state;
print('Tracking mode: ${state.trackingMode}');
// > 'Tracking mode: 1'

await BackgroundGeolocation.startGeofences();
state = await BackgroundGeolocation.state;
print('Tracking mode: ${state.trackingMode}');
// > 'Tracking mode: 0'