asyncGetStoreContentList static method

ProgressListener? asyncGetStoreContentList(
  1. ContentType type,
  2. void onCompleteCallback(
    1. GemError err,
    2. List<ContentStoreItem>? items,
    3. bool? isCached
    )
)

Asynchronously gets an online store content list.

Should not be used if the user is offline or has expired local content, otherwise will trigger the onCompleteCallback with a GemError different from GemError.success.

Parameters

  • IN type Content list type (see ContentType)
  • IN onCompleteCallback The listener object that implements the notification events associated with this operation.
    • IN err GemError.success on success, otherwise see GemError for other values
    • IN items List of content store items on success. Null on error
    • IN isCached True if the list is cached locally. False otherwise. Null on error.

Returns

  • The associated ProgressListener if the request can be started, null otherwise.

Throws

  • An exception if it fails to initialize.

Implementation

static ProgressListener? asyncGetStoreContentList(
  final ContentType type,
  final void Function(
    GemError err,
    List<ContentStoreItem>? items,
    bool? isCached,
  ) onCompleteCallback,
) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();
  final OperationResult resultString = staticMethod(
    'ContentStore',
    'asyncGetStoreContentList',
    args: <String, dynamic>{'type': type.id, 'listener': progListener.id},
  );

  if (resultString is Map && resultString.containsKey('gemApiError')) {
    final int errorCode = resultString['gemApiError'] as int;
    final GemError error = GemErrorExtension.fromCode(errorCode);
    if (error != GemError.success) {
      onCompleteCallback(error, null, null);
      return null;
    }
  }

  progListener.registerOnCompleteWithDataCallback((
    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'];
      onCompleteCallback(
        GemErrorExtension.fromCode(0),
        ContentStoreItemList.init(listId, 0).toList(),
        isCached,
      );
      //onCompleteCallback(err, result.getJson());
    } else {
      onCompleteCallback(GemErrorExtension.fromCode(err), null, null);
    }
  });
  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
  return progListener;
}