asyncGetStoreContentList static method
- ContentType type,
- void onComplete(
- GemError err,
- List<
ContentStoreItem> items, - bool isCached
Asynchronously request the online store content list for a specific content type.
Call this method when an active internet connection is available and the offline data on the device is not expired. Results are delivered through the provided completion callback.
Parameters
type: The ContentType to request (for example ContentType.roadMap or ContentType.viewStyleHighRes).onComplete: Required callback invoked when the operation completes. The function is called with:err— a GemError indicating the operation result (for exampleGemError.success,GemError.noConnection, etc.).items— aList<ContentStoreItem>containing the retrieved items whenerrisGemError.success, or an empty list on error.isCached—truewhen the returned list was retrieved from a local cache, otherwisefalse.
Returns
- A ProgressListener to monitor or cancel the request if it started successfully, or
nullwhen the request could not be started (for example when offline and no cached data is valid).
See also:
- getStoreContentList - Synchronously retrieve the last cached online content list.
Implementation
static ProgressListener? asyncGetStoreContentList(
final ContentType type,
final void Function(
GemError err,
List<ContentStoreItem> items,
bool isCached,
)
onComplete,
) {
final EventDrivenProgressListener progListener =
EventDrivenProgressListener();
final OperationResult resultString = staticMethod(
'ContentStore',
'asyncGetStoreContentList',
args: <String, dynamic>{'type': type.id, 'listener': progListener.id},
);
if (resultString.containsKey('gemApiError')) {
final int errorCode = resultString['gemApiError'] as int;
final GemError error = GemErrorExtension.fromCode(errorCode);
if (error != GemError.success) {
onComplete(error, <ContentStoreItem>[], false);
return null;
}
}
progListener.registerOnCompleteWithData((
final int err,
final String hint,
final Map<dynamic, dynamic> json,
) {
if (err == 0) {
final OperationResult contentStoreListString = staticMethod(
'ContentStore',
'getStoreContentList',
args: type.id,
);
final int listId =
contentStoreListString['result']['contentStoreListId'];
final bool isCached = contentStoreListString['result']['isCached'];
onComplete(
GemErrorExtension.fromCode(0),
ContentStoreItemList.init(listId).toList(),
isCached,
);
} else {
onComplete(
GemErrorExtension.fromCode(err),
<ContentStoreItem>[],
false,
);
}
});
GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
return progListener;
}