LogUploader constructor

LogUploader({
  1. void onLogStatusChanged(
    1. GemError error,
    2. String logPath,
    3. LogUploaderState? status,
    4. int? progress,
    )?,
})

Creates a LogUploader instance.

The optional onLogStatusChanged callback receives status updates during the lifecycle of an upload.

Parameters

  • onLogStatusChanged: Callback invoked to report upload progress and completion. The callback is called with:
    • error (GemError): GemError.success on success, or another error code if the operation failed.
    • logPath (String): The path of the log file associated with the event.
    • status (LogUploaderState?): The current upload state; null when error is not GemError.success.
    • progress (int?): Progress percentage (0–100) when available; null when not applicable.

Implementation

factory LogUploader({
  final void Function(
    GemError error,
    String logPath,
    LogUploaderState? status,
    int? progress,
  )?
  onLogStatusChanged,
}) {
  // create the listener first (so we have its pointer)
  final LogUploadListener listener = LogUploadListener((
    final String logPath,
    final int status,
    final int progress,
  ) {
    if (status < 0) {
      final GemError err = GemErrorExtension.fromCode(status);
      onLogStatusChanged?.call(err, logPath, null, null);
    } else {
      final LogUploaderState state = LogUploaderStateExtension.fromId(status);
      onLogStatusChanged?.call(GemError.success, logPath, state, progress);
    }
  });

  // call platform to create the native LogUploader and get its pointer id
  final String resultString = GemKitPlatform.instance.callCreateObject(
    jsonEncode(<String, Object>{
      'class': 'LogUploader',
      'args': listener.pointerId,
    }),
  );
  final dynamic decodedVal = jsonDecode(resultString);
  final int pointerId = decodedVal['result'] as int;

  // construct the Dart object (this calls super(pointerId) and registers once)
  final LogUploader instance = LogUploader._(pointerId, listener);

  // register the listener with the platform event system (if required)
  GemKitPlatform.instance.registerEventHandler(listener.pointerId, listener);

  return instance;
}