requestWikiInfo static method
EventHandler?
requestWikiInfo(
- Landmark landmark, {
- required void onComplete(
- GemError err,
- ExternalInfo? extraInfo
Requests Wikipedia information for landmark.
When available, the platform-side Wikipedia data is returned as an
ExternalInfo instance via the onComplete callback. The callback is
invoked with a GemError indicating success or the failure reason and
the ExternalInfo object on success.
The Landmark needs to have Wikipedia information available; use hasWikiInfo to check before requesting.
Parameters
landmark: The landmark for which to request Wikipedia information.onComplete: Callback invoked when the request completes. The callback receives:- GemError.success for
errand the ExternalInfo instance forextraInfoon success. - GemError.general describing the failure reason and
nullforextraInfoon error.
- GemError.success for
Returns
EventHandler?: A handler that can be used to cancel the pending request, ornullif the request could not be initiated.
Example:
if (!ExternalInfoService.hasWikiInfo(landmark)) {
print('The landmark does not have Wiki info.');
return;
}
ExternalInfoService.requestWikiInfo(landmark, onComplete: (err, info) {
if (err == GemError.success) {
print('Successfully retrieved Wiki info.');
// Use the retrieved info as needed
} else if (info != null) {
print('Failed to retrieve Wiki info.');
}
});
Implementation
static EventHandler? requestWikiInfo(
Landmark landmark, {
required void Function(GemError err, ExternalInfo? extraInfo) onComplete,
}) {
final (bool hasWikiInfo, ExternalInfo externalInfo) = _checkWikiInfo(
landmark,
);
if (!hasWikiInfo) {
onComplete(GemError.invalidInput, null);
return null;
}
final ExternalInfoHandler wikiListener = ExternalInfoHandler(externalInfo);
wikiListener.registerOnCompleteWithData((
final int err,
final String hint,
final Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(wikiListener.id);
final GemError error = GemErrorExtension.fromCode(err);
if (error == GemError.success) {
onComplete(error, externalInfo);
} else {
onComplete(error, null);
}
});
GemKitPlatform.instance.registerEventHandler(wikiListener.id, wikiListener);
objectMethod(
externalInfo.pointerId,
'ExternalInfo',
'requestWikiInfo',
args: <String, dynamic>{
'first': landmark.pointerId,
'second': wikiListener.id,
},
);
return wikiListener;
}