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
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
modelintodirectory, creating the directory if needed. -
fileIn(
String directory, PretrainedModel model) → File -
Where download will put
modelinsidedirectory. -
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
modelfrom.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- defaultBaseUrl → Uri
-
Where Facebook publishes the models.
final