getDatum method

  1. @override
Future<Datum> getDatum()
override

Returns the WeatherDatum for this location.

Implementation

@override
Future<Datum> getDatum() async {
  if (deviceManager.service != null) {
    try {
      final loc = await LocationManager().getLastKnownLocation();
      final Weather weather =
          await deviceManager.service!.currentWeatherByLocation(
        loc.latitude!,
        loc.longitude!,
      );

      return WeatherDatum.fromWeatherData(weather);
    } catch (error) {
      warning('$runtimeType - Error getting weather - $error');
      return ErrorDatum('$runtimeType Exception: $error');
    }
  }
  warning(
      '$runtimeType - no service available. Did you remember to add the WeatherService to the study protocol?');
  return ErrorDatum('$runtimeType - no service available.');
}