installWithProgress method
Installs the model with progress tracking
Returns a stream of progress percentages (0-100)
Note: Some sources may not support true progress:
- AssetSource: simulates progress (copy is instant)
- BundledSource: returns 100 immediately (no download)
- FileSource: returns 100 immediately (just registration)
Example:
await for (final progress in handler.installWithProgress(source)) {
print('Progress: $progress%');
}
Implementation
@override
Stream<int> installWithProgress(ModelSource source) async* {
if (source is! AssetSource) {
throw ArgumentError('AssetSourceHandler only supports AssetSource');
}
// Generate filename from path
final filename = path.basename(source.path);
// Copy asset file with REAL progress tracking (LargeFileHandler)
if (assetLoader is FlutterAssetLoader) {
// LargeFileHandler expects just filename - it resolves to app documents directory
await for (final progress in (assetLoader as FlutterAssetLoader)
.copyAssetToFileWithProgress(source.pathForLookupKey, filename)) {
yield progress;
}
} else {
// Fallback for other loaders (testing)
final targetPath = await fileSystem.getTargetPath(filename);
final assetData = await assetLoader.loadAsset(source.pathForLookupKey);
await fileSystem.writeFile(targetPath, assetData);
yield 100;
}
// Get target path for metadata (after file is copied)
final targetPath = await fileSystem.getTargetPath(filename);
final sizeBytes = await fileSystem.getFileSize(targetPath);
// Save metadata to repository
final modelInfo = ModelInfo(
id: filename,
source: source,
installedAt: DateTime.now(),
sizeBytes: sizeBytes,
type: ModelType.inference,
hasLoraWeights: false,
);
await repository.saveModel(modelInfo);
}