switchModel method
Implementation
Future<void> switchModel(String modelPath, [YOLOTask? task]) async {
final channel = _methodChannel;
if (channel == null || _viewId == null) return;
final resolvedModel = await YOLOModelResolver.resolve(
modelPath: modelPath,
task: task,
);
// Call the channel directly (not _invoke) so a native setModel failure propagates: the in-place-switch path in
// YOLOView relies on this throwing to revert the target and route to onModelError, instead of silently
// committing the new model and firing onModelLoad as if it succeeded.
try {
await channel.invokeMethod<void>('setModel', {
'modelPath': resolvedModel.modelPath,
'task': resolvedModel.task.name,
});
} catch (e) {
logInfo('YOLOViewController.setModel failed: $e');
rethrow;
}
}