ModelDownloader class

Fetches pretrained models and puts them in a directory of your choosing.

final downloader = ModelDownloader();
try {
  final file = await downloader.download(
    PretrainedModel.compact,
    directory: 'assets/models',
    onProgress: (p) => print(p),
  );
  final identifier = LanguageIdentifier.fromBytes(await file.readAsBytes());
} finally {
  await downloader.close();
}

A model already present in the directory is returned as is; pass force: true to fetch it again. The download goes to a .part file and is renamed into place only once it is complete and its header checks out, so an interrupted run never leaves a half-written model behind.

Constructors

ModelDownloader({Uri? baseUrl, HttpClient? httpClient})
Creates a downloader.

Properties

baseUrl → Uri
Where models are fetched from; ends with a slash.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future<void>
Releases the underlying HttpClient, unless it was passed in.
download(PretrainedModel model, {required String directory, bool force = false, void onProgress(DownloadProgress progress)?}) → Future<File>
Downloads model into directory, creating the directory if needed.
fileIn(String directory, PretrainedModel model) → File
Where download will put model inside directory.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
urlOf(PretrainedModel model) → Uri
The address download will fetch model from.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

defaultBaseUrl → Uri
Where Facebook publishes the models.
final