downloadModel method

Future<void> downloadModel({
  1. required OCRModule module,
  2. String? apiKey,
  3. String? token,
  4. PlatformType platformType = PlatformType.flutter,
  5. void onProgress(
    1. DownloadProgress
    )?,
})

Downloads a model from the server to disk.

module - The OCR module to download apiKey - API key for authentication (optional if token provided) token - Auth token (optional if apiKey provided) platformType - Platform identifier for telemetry onProgress - Callback for download progress updates

Throws ModelException on failure.

Implementation

Future<void> downloadModel({
  required OCRModule module,
  String? apiKey,
  String? token,
  PlatformType platformType = PlatformType.flutter,
  void Function(DownloadProgress)? onProgress,
}) async {
  //callback needs to be set before calling method or else it wont receive updates
  if (onProgress != null) {
    _currentProgressCallback = onProgress;
  }

  try {
    await _channel.invokeMethod('downloadModel', {
      'modelClass': _modelClassToInt(module.modelClass),
      'modelSize': _modelSizeToInt(module.modelSize),
      'apiKey': apiKey,
      'token': token,
      'platformType': platformType.value,
      'trackProgress': onProgress != null,
    });
  } on PlatformException catch (e) {
    _currentProgressCallback = null;
    throw _mapPlatformException(e, module);
  }
}