getHourlyForecast static method

ProgressListener getHourlyForecast({
  1. required int hours,
  2. required List<Coordinates> coords,
  3. void onComplete(
    1. GemError error,
    2. List<LocationForecast> locationForecasts
    )?,
})

Retrieves hourly weather forecast for specified coordinates.

Parameters

Returns

Also see:

Implementation

static ProgressListener getHourlyForecast({
  required final int hours,
  required final List<Coordinates> coords,
  final void Function(
    GemError error,
    List<LocationForecast> locationForecasts,
  )?
  onComplete,
}) {
  final LocationForecastList result = LocationForecastList.create();
  final EventDrivenProgressListener listener = EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(listener.id, listener);

  listener.registerOnCompleteWithData((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(listener.id);
    if (err == 0) {
      onComplete?.call(GemErrorExtension.fromCode(err), result.getJson());

      result.dispose();
    } else {
      onComplete?.call(GemErrorExtension.fromCode(err), <LocationForecast>[]);
    }
  });
  final OperationResult resultString = staticMethod(
    'Weather',
    'getHourlyForecast',
    args: <String, dynamic>{
      'hours': hours,
      'coords': coords,
      'result': result.id,
      'listener': listener.id,
    },
  );
  final GemError errCode = GemErrorExtension.fromCode(resultString['result']);
  if (errCode != GemError.success) {
    onComplete?.call(errCode, <LocationForecast>[]);
  }
  return listener;
}