LogUploader constructor
- void onLogStatusChanged(
- GemError error,
- String logPath,
- LogUploaderState? status,
- 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.successon 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;nullwhenerroris notGemError.success.progress(int?): Progress percentage (0–100) when available;nullwhen 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;
}