onStop method

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

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

Implementation

@override
Future<bool> onStop() async {
  if (_isRecording) {
    try {
      await _stopAudioRecording();
      debug(' $runtimeType [$hashCode] - Audio recording stopped.');

      // when stopping the audio sampling, stop recording and collect the measurement
      if (_data != null) {
        _data?.endRecordingTime = DateTime.now().toUtc();
        var measurement = Measurement(
            sensorStartTime:
                _data!.startRecordingTime!.microsecondsSinceEpoch,
            sensorEndTime: _data!.endRecordingTime?.microsecondsSinceEpoch,
            data: _data!);
        addMeasurement(measurement);
      }
    } catch (error) {
      warning('An error occurred trying to stop audio recording - $error');
      addError(error);
    }
  }
  return true;
}