buildModelDownloadTask function
DownloadTask
buildModelDownloadTask({})
Builds the DownloadTask for a model download.
Extracted so the shape can be asserted without a device — every field here is load-bearing and every one of them failed silently when wrong:
groupmust be SmartDownloader.downloadGroup, the SAME constantregisterCallbacksuses. A drift between the two ends means the task lands in a group nobody is registered for,_emitStatusUpdatefinds no callback and noupdateslistener, and the download hangs forever while background_downloader merely logs a warning (#383's class).updatesmust include progress, or the download looks frozen at 0%.retries: 0because retries are handled here with HTTP-aware logic; package-level retries would race that loop.priority— see SmartDownloader.downloadPriority.
Implementation
@visibleForTesting
DownloadTask buildModelDownloadTask({
required String taskId,
required String url,
required String? token,
required BaseDirectory baseDirectory,
required String directory,
required String filename,
required bool allowPause,
}) => DownloadTask(
taskId: taskId,
url: url,
group: SmartDownloader.downloadGroup,
headers: {
if (token != null) 'Authorization': 'Bearer $token',
'Connection': 'keep-alive',
// Attempt to work around CDN ETag issues
'Cache-Control': 'no-cache, no-store',
'Pragma': 'no-cache',
},
baseDirectory: baseDirectory,
directory: directory,
filename: filename,
requiresWiFi: false,
// Auto-detect: false for HuggingFace (weak ETags), true for others
allowPause: allowPause,
priority: SmartDownloader.downloadPriority,
retries: 0,
updates: Updates.statusAndProgress,
);