onMotionChange static method

void onMotionChange(
  1. dynamic callback(
    1. Location
    )
)

Subscribe to motionchange events

Your callback will be executed each time the device has changed-state between MOVING or STATIONARY.

Example

BackgroundGeolocation.onMotionChange((Location location) {
  if (location.isMoving) {
     print('[onMotionChange] Device has just started MOVING ${location}');
  } else {
     print('[onMotionChange] Device has just STOPPED:  ${location});
  }
});

Implementation

static void onMotionChange(Function(Location) callback) {
  if (_eventsMotionChange == null) {
    _eventsMotionChange = _eventChannelMotionChange
        .receiveBroadcastStream()
        .map((dynamic event) => Location(event));
  }
  _registerSubscription(_eventsMotionChange!.listen(callback), callback);
}