update method
- bool allowChargeNetwork, {
- void onStatusUpdated(
- ContentUpdaterStatus status
- void onProgressUpdated(
- int progress
- void onCompleteCallback(
- 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:
- GemError.success on success
- GemError.inUse if the update is already running
- GemError.notSupported if the update is not supported for the given ContentType
- GemError.noDiskSpace if there is not enough disk space on the device
- GemError.io if a file system error occurs
- Other GemError values for other errors
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;
}