getForecast static method
- required List<
WeatherDurationCoordinates> coords, - void onComplete(
- GemError,
- List<
LocationForecast> locationForecasts
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
coords: List of coordinates with duration offsets for forecast requests.onComplete: Callback invoked when the operation completes. The callback is called with:- GemError.success and non-empty LocationForecast list on success.
- GemError.invalidInput and empty list if the coordinates list is empty.
- GemError.resourceMissing and empty list if internal engine resource is missing.
- GemError.outOfRange and empty list if number of coordinates exceeds maxCoordinatesPerRequest.
- Other GemError values and empty list on other errors.
Returns
- ProgressListener: Progress listener for tracking the operation.
Also see:
- maxCoordinatesPerRequest — Maximum number of coordinates allowed per request.
Implementation
static ProgressListener getForecast({
required final List<WeatherDurationCoordinates> coords,
void Function(GemError, List<LocationForecast> locationForecasts)?
onComplete,
}) {
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.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',
'getForecast',
args: <String, dynamic>{
'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;
}