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! BundledSource) {
throw ArgumentError('BundledSourceHandler only supports BundledSource');
}
// Get platform-specific bundled resource path
// This path is used directly by the native layer (no copying needed)
final bundledPath = await fileSystem.getBundledResourcePath(source.resourceName);
// Get file size for metadata
final sizeBytes = await fileSystem.getFileSize(bundledPath);
// Save metadata to repository
final modelInfo = ModelInfo(
id: source.resourceName,
source: source,
installedAt: DateTime.now(),
sizeBytes: sizeBytes,
type: ModelType.inference,
hasLoraWeights: false,
);
await repository.saveModel(modelInfo);
}