getDownloadProgress method
Gets a stream of download progress updates for a specific task.
taskId The ID of the download 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> getDownloadProgress(String taskId) async* {
try {
await _channel.invokeMethod('getDownloadProgress', {
'task_id': taskId,
});
final eventChannel =
EventChannel('background_transfer/download_progress_$taskId');
yield* eventChannel.receiveBroadcastStream().map((progress) {
return (progress as num).toDouble();
});
} on PlatformException catch (e) {
throw Exception("Failed to get download progress: ${e.message}");
}
}