downloadActivityFile method
Downloads the recorded track of a synced activity to the device, for example on a new device.
The outcome of the download reaches ActivityStoreListener.registerOnActivityFileDownloaded.
Parameters
localActivityID: The local id of the activity.onComplete: Called with GemError.success when the download started, GemError.notSupported when ActivityStoreConfig.syncEnabled is false, or GemError.invalidInput when the activity is not found.
Returns
- The ProgressListener of the call, or null when it could not start.
Implementation
ProgressListener? downloadActivityFile(
int localActivityID, {
void Function(GemError error)? onComplete,
}) {
final EventDrivenProgressListener progressListener =
EventDrivenProgressListener();
GemKitPlatform.instance.registerEventHandler(
progressListener.id,
progressListener,
);
progressListener.registerOnCompleteWithData((
int err,
String hint,
Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(progressListener.id);
onComplete?.call(GemErrorExtension.fromCode(err));
});
final OperationResult resultString = objectMethod(
pointerId,
'ActivityStore',
'downloadActivityFile',
args: <String, dynamic>{
'id': localActivityID,
'listener': progressListener.id,
},
);
final GemError errorCode = GemErrorExtension.fromCode(
resultString['result'],
);
if (errorCode != GemError.success) {
onComplete?.call(errorCode);
return null;
}
return progressListener;
}