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:
Size get size- Return the dimensions for automatic hit testingWidget 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 yoursize - 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, Set<
String> initialDependencies = const {}, Offset offset = Offset.zero, Map<String, dynamic> metadata = const {}})
Properties
- bounds → Rect
-
Automatically calculated bounding rectangle for hit testing.
no setter
- currentIsVisible → bool
-
The current visibility state (non-reactive).
no setter
- currentPosition → Offset
-
The current logical position value (non-reactive).
no setter
- currentSelected → bool
-
The current selection state (non-reactive).
no setter
- currentVisualPosition → Offset
-
The current visual (snapped) position value (non-reactive).
no setter
- currentZIndex → int
-
The current z-index value (non-reactive).
no setter
-
dependencies
→ ObservableSet<
String> -
Reactive observable set of node IDs this annotation depends on.
no setter
- hasAnyDependencies → bool
-
Whether this annotation has any node dependencies.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
Unique identifier for this annotation.
final
- isInteractive → bool
-
Whether this annotation responds to user interactions.
final
-
isVisible
→ Observable<
bool> -
Reactive observable for the annotation's visibility state.
no setter
-
metadata
→ Map<
String, dynamic> -
Additional metadata for custom data storage.
final
- offset → Offset
-
Offset from dependent node position (for following annotations).
final
-
position
→ Observable<
Offset> -
Reactive observable for the annotation's logical position.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
selected
→ Observable<
bool> -
Reactive observable for the annotation's selection state.
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
→ Observable<
Offset> -
Reactive observable for the annotation's visual position.
no setter
-
zIndex
→ Observable<
int> -
Reactive observable for the annotation's z-index (rendering order).
no setter
Methods
-
addDependency(
String nodeId) → void - Adds a node dependency to this annotation.
-
buildWidget(
BuildContext context) → Widget - Builds the visual representation of the annotation.
-
clearDependencies(
) → void - Clears all node dependencies from this 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.
-
hasDependency(
String nodeId) → bool - Checks if this annotation depends on a specific node.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeDependency(
String nodeId) → void - Removes a node dependency from this annotation.
-
setPosition(
Offset newPosition) → void - Sets the annotation's logical position.
-
setSelected(
bool selected) → void - Sets the annotation's selection state.
-
setVisible(
bool visible) → void - Sets the annotation's visibility state.
-
setVisualPosition(
Offset snappedPosition) → void - Updates the visual position (used for rendering with grid snapping).
-
setZIndex(
int newZIndex) → void - Sets the annotation's z-index (rendering order).
-
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
Static Methods
-
fromJsonByType(
Map< String, dynamic> json) → Annotation - Factory method for creating annotations from JSON based on type.