LogUploader constructor

LogUploader({
  1. @Deprecated('Use onLogStatusChanged instead') void onLogStatusChangedCallback(
    1. GemError error,
    2. String logPath,
    3. LogUploaderState? status,
    4. int? progress,
    )?,
  2. void onLogStatusChanged(
    1. GemError error,
    2. String logPath,
    3. LogUploaderState? status,
    4. int? progress,
    )?,
})

Creates a LogUploader instance.

Parameters

  • IN onLogStatusChanged Callback to be called when the log status changes.
    • IN error The error code of the upload.
    • IN logPath The path to the log file to upload.
    • IN status The status of the log upload.
    • IN progress The progress of the log upload.

If the upload is successful, the error code will be GemError.success. If not, it will be different from GemError.success and status and progress will be null.

Implementation

factory LogUploader({
  @Deprecated('Use onLogStatusChanged instead')
  final void Function(
    GemError error,
    String logPath,
    LogUploaderState? status,
    int? progress,
  )? onLogStatusChangedCallback,
  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);
        onLogStatusChangedCallback?.call(err, logPath, null, null);
        onLogStatusChanged?.call(err, logPath, null, null);
      } else {
        final LogUploaderState state =
            LogUploaderStateExtension.fromId(status);
        onLogStatusChangedCallback?.call(
            GemError.success, logPath, state, progress);
        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;
}