startDownload method
Starts a file download operation in the background.
fileUrl The URL of the file to download.
savePath The local path where the downloaded file should be saved.
headers Optional HTTP headers to include in the download request.
Returns a task ID string that can be used to track the download progress or cancel the operation.
Throws an Exception if the download fails to start.
Implementation
@override
Future<String> startDownload({
required String fileUrl,
required String savePath,
Map<String, String>? headers,
}) async {
try {
final taskId = await _channel.invokeMethod('startDownload', {
'file_url': fileUrl,
'output_path': savePath,
'headers': headers,
});
return taskId as String;
} on PlatformException catch (e) {
throw Exception("Failed to start download: ${e.message}");
}
}