asyncGetStoreContentList static method

ProgressListener? asyncGetStoreContentList(
  1. ContentType type,
  2. void onComplete(
    1. GemError err,
    2. List<ContentStoreItem> items,
    3. 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 example GemError.success, GemError.noConnection, etc.).
    • items — a List<ContentStoreItem> containing the retrieved items when err is GemError.success, or an empty list on error.
    • isCachedtrue when the returned list was retrieved from a local cache, otherwise false.

Returns

  • A ProgressListener to monitor or cancel the request if it started successfully, or null when the request could not be started (for example when offline and no cached data is valid).

See also:

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;
}