updateActivity method

ProgressListener? updateActivity(
  1. Activity activity, {
  2. void onComplete(
    1. GemError error
    )?,
})

Saves the changes made to a local activity and queues it for sync.

Saved are the title, the location, the metrics and the sport type, effort, visibility and long description of Activity.record; the store sets Activity.updatedAtMillis.

Parameters

Returns

Implementation

ProgressListener? updateActivity(
  Activity activity, {
  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',
    'updateActivity',
    args: <String, dynamic>{
      'activity': activity.toJson(),
      'listener': progressListener.id,
    },
  );
  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );

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

  return progressListener;
}