getMeasurement method

  1. @override
Future<Measurement> getMeasurement()
override

Get the Calendar measurement.

Implementation

@override
Future<Measurement> getMeasurement() async {
  if (_calendars == null) await _retrieveCalendars();

  if (_calendars != null) {
    _events = [];
    _calendarIterator = _calendars!.iterator;

    if (_calendarIterator.moveNext()) {
      await _retrieveEvents(_calendarIterator.current);
    }

    return Measurement(
      sensorStartTime: startDate!.microsecondsSinceEpoch,
      sensorEndTime: endDate?.microsecondsSinceEpoch,
      data: Calendar(startDate!, endDate!)..calendarEvents = _events,
    );
  } else {
    return Measurement.fromData(Error(
        message: 'Permission to collect calendar entries not granted.'));
  }
}