getForecast static method

ProgressListener getForecast({
  1. required List<WeatherDurationCoordinates> coords,
  2. void onComplete(
    1. GemError error,
    2. List<LocationForecast> locationForecasts
    )?,
  3. CoverageGeometry coverageGeometry = CoverageGeometry.none,
})

Retrieves weather forecast for coordinates at specified future times.

The duration in each WeatherDurationCoordinates specifies the time offset into the future for which the forecast is requested.

Parameters

Returns

Also see:

Implementation

static ProgressListener getForecast({
  required List<WeatherDurationCoordinates> coords,
  void Function(GemError, List<LocationForecast> locationForecasts)?
  onComplete,
  CoverageGeometry coverageGeometry = CoverageGeometry.none,
}) {
  for (final WeatherDurationCoordinates coord in coords) {
    if (coord.coordinates.latitude.abs() > 90 ||
        coord.coordinates.longitude.abs() > 180) {
      onComplete?.call(GemError.invalidInput, <LocationForecast>[]);

      return EventDrivenProgressListener();
    }
  }

  final LocationForecastList result = LocationForecastList();
  final EventDrivenProgressListener listener = EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(listener.id, listener);

  listener.registerOnCompleteWithData((
    int err,
    String hint,
    Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(listener.id);
    if (err == 0) {
      onComplete?.call(GemErrorExtension.fromCode(err), result.json);
      result.dispose();
    } else {
      onComplete?.call(GemErrorExtension.fromCode(err), <LocationForecast>[]);
    }
  });
  final OperationResult resultString = staticMethod(
    'Weather',
    'getForecast',
    args: <String, dynamic>{
      'coords': coords,
      'result': result.id,
      'listener': listener.id,
      'geometry': coverageGeometry.id,
    },
  );
  final GemError errCode = GemErrorExtension.fromCode(resultString['result']);
  if (errCode != GemError.success) {
    onComplete?.call(errCode, <LocationForecast>[]);
  }
  return listener;
}