createStickyNote method

StickyAnnotation createStickyNote({
  1. required Offset position,
  2. required String text,
  3. String? id,
  4. double width = 200.0,
  5. double height = 100.0,
  6. Color color = const Color(0xFFFFF59D),
  7. Offset offset = Offset.zero,
})

Creates and adds a sticky note annotation to the graph.

Sticky notes are floating text annotations that can be placed anywhere on the canvas.

Parameters:

  • position: Position in graph coordinates
  • text: The text content of the sticky note
  • id: Optional custom ID (auto-generated if not provided)
  • width: Width of the sticky note (default: 200.0)
  • height: Height of the sticky note (default: 100.0)
  • color: Background color (default: light yellow)
  • offset: Optional offset for positioning (default: Offset.zero)

Returns the created StickyAnnotation.

Example:

controller.createStickyNote(
  position: Offset(100, 100),
  text: 'Important note here',
  color: Colors.yellow,
);

Implementation

StickyAnnotation createStickyNote({
  required Offset position,
  required String text,
  String? id,
  double width = 200.0,
  double height = 100.0,
  Color color = const Color(0xFFFFF59D), // Light yellow
  Offset offset = Offset.zero,
}) {
  final annotation = annotations.createStickyAnnotation(
    id: id ?? 'sticky-${DateTime.now().millisecondsSinceEpoch}',
    position: position,
    text: text,
    width: width,
    height: height,
    color: color,
    offset: offset,
  );
  addAnnotation(annotation);
  return annotation;
}