ensureLoaded static method
Future<void>
ensureLoaded({
- required String? modelId,
- required ModelCategory category,
- LoadOptions? options,
- bool downloadIfNeeded = true,
Make modelId resident under category, downloading it when absent.
A null modelId leaves whatever is already loaded in place; commons
surfaces a structured error if nothing is.
Throws SDKException when the model is unknown, cannot be fetched, or fails to load.
Implementation
static Future<void> ensureLoaded({
required String? modelId,
required ModelCategory category,
LoadOptions? options,
bool downloadIfNeeded = true,
}) async {
if (!DartBridge.isInitialized) {
throw SDKException.notInitialized();
}
if (modelId == null || modelId.isEmpty) {
return;
}
await DartBridge.ensureServicesReady();
final current = await RunAnywhereModelLifecycle.shared.current(
model_pb.CurrentModelRequest(category: category),
);
if (current.found && current.modelId == modelId) {
return;
}
if (downloadIfNeeded) {
await _downloadIfAbsent(modelId);
}
await load(modelId: modelId, category: category, options: options);
}