switchModel method
Switches the model on the associated YoloView.
This method allows switching to a different model without recreating the view. The view must be initialized (have a viewId) before calling this method.
newModelPath The official model ID, local path, asset path, or URL for the new model
newTask The task type for the new model when metadata is missing
throws StateError if the view is not initialized
throws ModelLoadingException if the model switch fails
Implementation
Future<void> switchModel(String newModelPath, [YOLOTask? newTask]) async {
await _ensureResolved();
final resolvedModel = await YOLOModelResolver.resolve(
modelPath: newModelPath,
task: newTask,
);
await _modelManager!.switchModel(
resolvedModel.modelPath,
resolvedModel.task,
);
_resolvedModel = resolvedModel;
_inference = YOLOInference(
channel: _channel,
instanceId: _instanceId,
task: resolvedModel.task,
);
_isInitialized = true;
}