onStart method

  1. @override
Future<bool> onStart()
override

Callback when this executor is started. Returns true if successfully started, false otherwise.

Implementation

@override
Future<bool> onStart() async {
  if (await requestPermissions()) {
    Duration? interval = samplingConfiguration?.interval;
    if (interval != null) {
      // create a recurrent timer that gets the data point every [frequency].
      _timer ??= Timer.periodic(interval, (Timer t) async {
        try {
          var measurement = await getMeasurement();
          if (measurement != null) addMeasurement(measurement);
        } catch (error) {
          addError(error);
        }
      });
    } else {
      warning(
          '$runtimeType - no valid interval found in sampling configuration: $samplingConfiguration. '
          'Is a valid IntervalSamplingConfiguration provided?');
      return false;
    }
    return true;
  } else {
    return false;
  }
}