setEventSendingEnabled method

void setEventSendingEnabled(
  1. bool enabled, {
  2. bool flush = true,
})

Enable or disable event sending. When disabling event sending it may be desirable to flush pending events. For instance in a mobile app on transition to the background. This flush attempt will only be made if the network is available.

Implementation

void setEventSendingEnabled(bool enabled, {bool flush = true}) {
  // The mode is not changing, so no action is required.
  if (_eventSendingEnabled == enabled) {
    _logger.debug('Event sending already in desired state. No changes made.');
    return;
  }

  if (!enabled && flush && _networkAvailable) {
    // The event processor will asynchronously start this and it will
    // not be interrupted by stopping the processor. Stopping it will just
    // stop all the timers, not any outstanding requests.
    _logger.debug('Flushing events on event disable transition.');
    _eventProcessor?.flush();
  }
  _eventSendingEnabled = enabled;
  _updateEventSendingState();
}