selectAnnotation method

void selectAnnotation(
  1. String annotationId, {
  2. bool toggle = false,
})

Selects an annotation in the graph.

Automatically clears selections of other element types (nodes, connections). Requests canvas focus.

Triggers the onAnnotationSelected callback after selection changes.

Parameters:

  • annotationId: The ID of the annotation to select
  • toggle: If true, toggles the annotation's selection state. If false (default), clears other selections and selects only this annotation.

Implementation

void selectAnnotation(String annotationId, {bool toggle = false}) {
  runInAction(() {
    // Clear other element types' selections
    clearNodeSelection();
    clearConnectionSelection();
  });

  annotations.selectAnnotation(annotationId, toggle: toggle);

  // Fire selection callback with current selection state
  final selectedAnnotation = annotations.isAnnotationSelected(annotationId)
      ? annotations.getAnnotation(annotationId)
      : null;
  callbacks.onAnnotationSelected?.call(selectedAnnotation);

  canvasFocusNode.requestFocus();
}