getUploadProgress method
Gets a stream of upload progress updates for a specific task.
Monitors WorkManager progress updates through a broadcast stream.
taskId The ID of the upload task to track.
Returns a stream that emits progress values between 0.0 and 1.0.
Throws an Exception if tracking the progress fails.
Implementation
@override
Stream<double> getUploadProgress(String taskId) async* {
try {
await _channel.invokeMethod('getUploadProgress', {
'task_id': taskId,
});
final eventChannel =
EventChannel('background_transfer/upload_progress_$taskId');
yield* eventChannel.receiveBroadcastStream().map((progress) {
if (progress is String && progress.startsWith('error:')) {
throw Exception(progress.substring(6));
}
return (progress as num).toDouble();
});
} on PlatformException catch (e) {
throw Exception("Failed to get upload progress: ${e.message}");
}
}