install method
Installs the model from the given source
This method performs the actual installation:
- NetworkSource: downloads from URL
- AssetSource: copies from Flutter assets
- BundledSource: accesses native resources
- FileSource: registers external file path
Throws:
- UnsupportedError if this handler doesn't support the source type
- ArgumentError if the source is invalid
- Platform-specific exceptions for download/file errors
Implementation
@override
Future<void> install(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 directly using LargeFileHandler (no memory loading!)
// This handles large files (290MB+) efficiently
if (assetLoader is FlutterAssetLoader) {
// LargeFileHandler expects just filename - it resolves to app documents directory
await (assetLoader as FlutterAssetLoader).copyAssetToFile(
source.pathForLookupKey,
filename, // Just filename, not full path
);
} else {
// Fallback for other loaders (testing)
final targetPath = await fileSystem.getTargetPath(filename);
final assetData = await assetLoader.loadAsset(source.pathForLookupKey);
await fileSystem.writeFile(targetPath, assetData);
}
// 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);
}