update method

ProgressListener? update(
  1. bool allowChargeNetwork, {
  2. void onStatusUpdated(
    1. ContentUpdaterStatus status
    )?,
  3. void onProgressUpdated(
    1. int progress
    )?,
  4. void onCompleteCallback(
    1. GemError error
    )?,
})

Start / resume the update process.

Parameters

  • IN allowChargeNetwork Allow charging network
  • IN onStatusUpdated Callback that gets triggered when the status of the updater changes. Gets called with the associated ContentUpdaterStatus.
  • IN onProgressUpdated Callback that gets triggered when the progress of the updater changes. Gets called with the associated progress.
  • IN onCompleteCallback Callback that gets triggered when the update process is completed. Gets called with the associated GemError:

Returns

  • Associated ProgressListener for this operation if the update can be started otherwise null.

Throws

  • An exception if it fails.

Implementation

ProgressListener? update(
  final bool allowChargeNetwork, {
  final void Function(ContentUpdaterStatus status)? onStatusUpdated,
  final void Function(int progress)? onProgressUpdated,
  final void Function(GemError error)? onCompleteCallback,
}) {
  final EventDrivenProgressListener progressListener =
      EventDrivenProgressListener();

  if (onStatusUpdated != null) {
    progressListener.registerOnNotifyStatusChanged(
      (final int status) =>
          onStatusUpdated(ContentUpdaterStatusExtension.fromId(status)),
    );
  }

  if (onProgressUpdated != null) {
    progressListener.registerOnProgressCallback(
      (final int progress) => onProgressUpdated(progress),
    );
  }

  if (onCompleteCallback != null) {
    progressListener.registerOnCompleteWithDataCallback(
      (final int err, final String hint, final Map<dynamic, dynamic> json) =>
          onCompleteCallback(GemErrorExtension.fromCode(err)),
    );
  }

  GemKitPlatform.instance.registerEventHandler(
    progressListener.id,
    progressListener,
  );

  final OperationResult resultString = objectMethod(
    _pointerId,
    'ContentUpdater',
    'update',
    args: <String, dynamic>{
      'allowChargeNetwork': allowChargeNetwork,
      'listener': progressListener.id,
    },
  );

  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );
  if (errorCode != GemError.success) {
    onCompleteCallback?.call(errorCode);
    return null;
  }

  return progressListener;
}