Annotation class abstract

Base annotation class that can be placed in the node flow

Creating Custom Annotations

To create a custom annotation, simply extend this class and implement:

  1. Size get size - Return the dimensions for automatic hit testing
  2. Widget buildWidget(BuildContext context) - Return your custom widget

Example:

class CustomAnnotation extends Annotation {
  final String title;
  final double width;
  final double height;

  CustomAnnotation({
    required super.id,
    required Offset position,
    required this.title,
    this.width = 150.0,
    this.height = 80.0,
  }) : super(
    type: 'custom',
    initialPosition: position,
  );

  @override
  Size get size => Size(width, height);

  @override
  Widget buildWidget(BuildContext context) {
    return Container(
      width: width,
      height: height,
      decoration: BoxDecoration(
        color: Colors.purple,
        borderRadius: BorderRadius.circular(12),
      ),
      child: Center(child: Text(title)),
    );
  }

  @override
  Map<String, dynamic> toJson() => {'title': title, 'width': width, 'height': height};

  @override
  void fromJson(Map<String, dynamic> json) {
    // Update properties from json if needed
  }
}

The framework automatically handles:

  • Hit testing via containsPoint() using your size
  • Positioning and coordinate transforms
  • Selection visual feedback
  • Drag and drop interactions (if isInteractive = true)
  • Z-index layering and rendering order
  • MobX reactivity for position and visibility changes
Implementers

Constructors

Annotation({required String id, required String type, required Offset initialPosition, int initialZIndex = 0, bool initialIsVisible = true, bool selected = false, bool isInteractive = true, Map<String, dynamic> metadata = const {}})

Properties

bounds Rect
Automatically calculated bounding rectangle for hit testing.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier for this annotation.
final
isEmpty bool
Whether this annotation is considered "empty" and has no content.
no setter
isInteractive bool
Whether this annotation responds to user interactions.
final
isVisible bool
Whether the annotation is visible.
getter/setter pair
layer AnnotationRenderLayer
The rendering layer for this annotation.
no setter
metadata Map<String, dynamic>
Additional metadata for custom data storage.
final
monitoredNodeIds Set<String>
The set of node IDs that this annotation monitors for position/size changes.
no setter
monitorNodes bool
Whether this annotation should receive automatic node lifecycle callbacks.
no setter
position Offset
The annotation's logical position (before grid snapping).
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selected bool
Whether the annotation is currently selected.
getter/setter pair
shouldRemoveWhenEmpty bool
Whether this annotation should be automatically removed when empty.
no setter
size Size
The dimensions of the annotation for automatic hit testing.
no setter
type String
The type of annotation (e.g., 'sticky', 'group', 'marker').
final
visualPosition Offset
The annotation's visual position (after grid snapping).
getter/setter pair
zIndex int
The annotation's z-index (rendering order within its layer).
getter/setter pair

Methods

buildWidget(BuildContext context) Widget
Builds the visual representation of the annotation.
containsPoint(Offset point) bool
Automatic hit testing based on position and size.
fromJson(Map<String, dynamic> json) → void
Deserializes JSON data into this annotation.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDragEnd() → void
Called when a drag operation ends on this annotation.
onDragMove(Offset delta, AnnotationDragContext context) → void
Called during drag with the movement delta.
onDragStart(AnnotationDragContext context) → void
Called when a drag operation starts on this annotation.
onNodeAdded(String nodeId, Rect nodeBounds, AnnotationDragContext context) bool
Called when a new node is added to the graph.
onNodeMoved(String nodeId, Offset newPosition, AnnotationDragContext context) → void
Called when a node's position changes.
onNodeResized(String nodeId, Size newSize, AnnotationDragContext context) → void
Called when a node's size changes.
onNodesDeleted(Set<String> nodeIds, AnnotationDragContext context) → void
Called when nodes are deleted from the graph.
onNodeVisibilityChanged(String nodeId, bool isVisible) → void
Called when a node's visibility changes.
onSelectionChanged(Set<String> selectedNodeIds) → void
Called when the node selection changes.
toJson() Map<String, dynamic>
Serializes this annotation to JSON.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited