addActivityFile method

ProgressListener? addActivityFile({
  1. required int localActivityID,
  2. required StoredActivityFile file,
  3. required String localFilePath,
  4. void onComplete(
    1. GemError error,
    2. int localFileID
    )?,
})

Attaches a device file, such as a route thumbnail, photo or video, to a local activity.

The file is queued for upload with the activity.

Parameters

  • localActivityID: The local id of the activity.
  • file: The type, size, creation time and location of the file; the ids are assigned by the store.
  • localFilePath: The absolute device path of the file.
  • onComplete: Called with GemError.success and the local id of the file (StoredActivityFile.localFileID), or with GemError.general and -1 when it could not be attached.

Returns

Implementation

ProgressListener? addActivityFile({
  required int localActivityID,
  required StoredActivityFile file,
  required String localFilePath,
  void Function(GemError error, int localFileID)? 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), json['result']);
  });

  final OperationResult resultString = objectMethod(
    pointerId,
    'ActivityStore',
    'addActivityFile',
    args: <String, dynamic>{
      'localActivityID': localActivityID,
      'file': file.toJson(),
      'localFilePath': localFilePath,
      'listener': progressListener.id,
    },
  );
  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );

  if (errorCode != GemError.success) {
    onComplete?.call(errorCode, -1);
    return null;
  }

  return progressListener;
}