update method

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

Starts or resumes the content update process.

Initiates downloading of available updates for the updater's contentType. The download runs in background and reports status and progress via optional callbacks. If the operation cannot be started the provided onComplete callback will be invoked with the corresponding GemError code and the method returns null.

Parameters

Returns

Also see:

  • apply: Apply a downloaded update when ready.

Implementation

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

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

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

  if (onComplete != null) {
    progressListener.registerOnCompleteWithData(
      (final int err, final String hint, final Map<dynamic, dynamic> json) =>
          onComplete(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) {
    onComplete?.call(errorCode);
    return null;
  }

  return progressListener;
}