getDailyForecast static method

ProgressListener getDailyForecast({
  1. required int days,
  2. required List<Coordinates> coords,
  3. required void onCompleteCallback(
    1. GemError error,
    2. List<LocationForecast> locationForecasts
    ),
})

Async gets forecast weather for a list of coordinates and timestamps.

Parameters

  • IN days The number of days for which the forecast is requested (value should be <= 10).
  • IN coords The coordinates list for which the forecast is requested.
  • IN onCompleteCallback The callback which will be called when the operation completes.
    • Will be called with GemError.success error and non-empty locationForecasts upon success.
    • Will be called with GemError.invalidInput error and empty locationForecasts if the coordinates list is empty or if the number of days is negative.
    • Will be called with GemError.resourceMissing error and empty locationForecasts if the internal engine resource is missing
    • Will be called with GemError.outOfRange error and empty locationForecasts if number of coordinates or the number of days is greater than the maximum allowed.
    • Will be called with other GemError values and empty locationForecasts on other errors

Returns

Throws

  • An exception if it fails.

Implementation

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

  listener.registerOnCompleteWithDataCallback((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(listener.id);
    if (err == 0) {
      onCompleteCallback(GemErrorExtension.fromCode(err), result.getJson());
      result.dispose();
    } else {
      onCompleteCallback(
        GemErrorExtension.fromCode(err),
        <LocationForecast>[],
      );
    }
  });
  final OperationResult resultString = staticMethod(
    'Weather',
    'getDailyForecast',
    args: <String, dynamic>{
      'days': days,
      'coords': coords,
      'result': result.id,
      'listener': listener.id,
    },
  );
  final GemError errCode = GemErrorExtension.fromCode(resultString['result']);
  if (errCode != GemError.success) {
    onCompleteCallback(errCode, <LocationForecast>[]);
  }
  return listener;
}