getCurrent static method
- required List<
Coordinates> coords, - void onComplete(
- GemError error,
- List<
LocationForecast> locationForecasts
Retrieves current weather for specified coordinates.
Parameters
coords: List of coordinates for which to fetch current weather.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 getCurrent({
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 resultOperation = staticMethod(
'Weather',
'getCurrent',
args: <String, dynamic>{
'coords': coords,
'result': result.id,
'listener': listener.id,
},
);
final GemError errCode = GemErrorExtension.fromCode(
resultOperation['result'],
);
if (errCode != GemError.success) {
onComplete?.call(errCode, <LocationForecast>[]);
}
return listener;
}