asyncDownload method

ProgressListener asyncDownload(
  1. void onCompleteCallback(
    1. GemError err
    ), {
  2. void onProgressCallback(
    1. int progress
    )?,
  3. bool allowChargedNetworks = false,
  4. DataSavePolicy savePolicy = DataSavePolicy.useDefault,
  5. ContentDownloadThreadPriority priority = ContentDownloadThreadPriority.defaultPriority,
})

Asynchronous start/resume the download of the content store product content.

Requires automatic map rendering. Disables the cursor if enabled.

Parameters

  • IN onCompleteCallback Object that implements notification event associated with operation completion. Cannot be empty. Returns GemError.success on success, otherwise see GemError for other values.
  • IN onProgressCallback Object that implements notification event associated with operation progress.
  • IN allowChargedNetworks Flag whether to allow charged networks. If true, it will override SdkSettings.setAllowOffboardServiceOnExtraChargedNetwork ( [ServiceGroupType.contentService, false ).
  • IN savePolicy Specify where the download will be made (optional).

Returns

Throws

  • An exception if it fails

Implementation

ProgressListener asyncDownload(
  final void Function(GemError err) onCompleteCallback, {
  final void Function(int progress)? onProgressCallback,
  final bool allowChargedNetworks = false,
  final DataSavePolicy savePolicy = DataSavePolicy.useDefault,
  final ContentDownloadThreadPriority priority =
      ContentDownloadThreadPriority.defaultPriority,
}) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();
  final OperationResult resultString = objectMethod(
    _pointerId,
    'ContentStoreItem',
    'asyncDownload',
    args: <String, dynamic>{
      'listener': progListener.id,
      'allowChargedNetworks': allowChargedNetworks,
      'savePolicy': savePolicy.id,
      'priority': priority.id,
    },
  );

  if (resultString is Map && resultString.containsKey('error')) {
    onCompleteCallback(GemErrorExtension.fromCode(resultString['error']));
    return EventDrivenProgressListener.init(0);
  }
  if (onProgressCallback != null) {
    progListener.registerOnProgressCallback((final int p0) {
      onProgressCallback(p0);
    });
  }
  progListener.registerOnCompleteWithDataCallback((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    if (err == 0) {
      onCompleteCallback(GemErrorExtension.fromCode(0));
      //onCompleteCallback(err, result.getJson());
    } else {
      onCompleteCallback(GemErrorExtension.fromCode(err));
    }
  });
  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
  return progListener;
}