download method

  1. @override
Future<void> download(
  1. String url,
  2. String targetPath, {
  3. String? token,
})
override

Downloads a file from URL to target path

Parameters:

  • url: Source URL (must be HTTP/HTTPS)
  • targetPath: Full path where file should be saved
  • token: Optional authentication token

Throws:

  • NetworkException for network errors
  • FileSystemException for file write errors

Implementation

@override
Future<void> download(String url, String targetPath, {String? token}) async {
  await _ensureInitialized();

  final task = DownloadTask(
    url: url,
    filename: targetPath,
    headers: token != null ? {'Authorization': 'Bearer $token'} : {},
    updates: Updates.statusAndProgress,
  );

  final result = await _downloader.download(task);

  if (result.status != TaskStatus.complete) {
    throw _createDownloadException(result.status, null, null);
  }
}