installWithProgress method

  1. @override
Stream<int> installWithProgress(
  1. ModelSource source
)
override

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! BundledSource) {
    throw ArgumentError('BundledSourceHandler only supports BundledSource');
  }

  // Get platform-specific bundled resource path
  final bundledPath = await fileSystem.getBundledResourcePath(source.resourceName);

  // Bundled resources are immediately available, report 100% after verification
  yield 100;

  // 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);
}