update method
- bool allowChargeNetwork, {
- void onStatusUpdated(
- ContentUpdaterStatus status
- void onProgressUpdated(
- int progress
- void onComplete(
- 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
allowChargeNetwork: Whether updates are allowed to proceed on metered/charged networks (mobile data).onStatusUpdated: Optional callback invoked when the updater status changes. Receives a ContentUpdaterStatus. Apply the update when the status is ContentUpdaterStatus.fullyReady or ContentUpdaterStatus.partiallyReady.onProgressUpdated: Optional callback invoked when download progress updates. Receives an integer 0..100.onComplete: Optional callback invoked when the update operation completes or fails. Receives a GemError.- GemError.success when the update finishes successfully.
- GemError.inUse when the update is already running and cannot be started.
- GemError.notSupported when updates are not supported for the contentType.
- GemError.noDiskSpace when there is insufficient device storage to download the update.
- GemError.io when a filesystem-related error occurred.
- Other GemError values for additional failure reasons.
Returns
- ProgressListener? : The associated ProgressListener for tracking the operation if it was started, otherwise
null.
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;
}