switchModel method

Future<void> switchModel(
  1. String modelPath,
  2. YOLOTask task
)

Switches to a different YOLO model.

This method allows changing the model without recreating the entire view. The view must be created before calling this method.

Parameters:

  • modelPath: Path to the new model file
  • task: The YOLO task type for the new model

Example:

await controller.switchModel(
  'assets/models/yolov8s.mlmodel',
  YOLOTask.segment,
);

@param modelPath The path to the new model file @param task The task type for the new model

Implementation

Future<void> switchModel(String modelPath, YOLOTask task) async {
  if (_methodChannel == null || _viewId == null) {
    logInfo(
      'YoloViewController: Warning - Cannot switch model, view not yet created',
    );
    return;
  }
  try {
    logInfo('YoloViewController: Switching model with viewId: $_viewId');

    // Call the platform method on the view's specific method channel
    await _methodChannel!.invokeMethod('setModel', {
      'modelPath': modelPath,
      'task': task.name,
    });

    logInfo(
      'YoloViewController: Model switched successfully to $modelPath with task ${task.name}',
    );
  } catch (e) {
    logInfo('YoloViewController: Error switching model: $e');
    rethrow;
  }
}