createCommentNode method

CommentNode<T> createCommentNode({
  1. required Offset position,
  2. required String text,
  3. required T data,
  4. String? id,
  5. double width = 200.0,
  6. double height = 100.0,
  7. Color color = const Color(0xFFFFF59D),
})

Creates and adds a comment node to the graph.

Comment nodes are floating text elements that can be placed anywhere on the canvas. They support inline editing and auto-grow when text exceeds bounds.

Parameters:

  • position: Position in graph coordinates
  • text: The text content of the comment
  • data: Custom data of type T associated with this node
  • id: Optional custom ID (auto-generated if not provided)
  • width: Width of the comment (default: 200.0)
  • height: Height of the comment (default: 100.0)
  • color: Background color (default: light yellow)

Returns the created CommentNode.

Example:

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

Implementation

CommentNode<T> createCommentNode({
  required Offset position,
  required String text,
  required T data,
  String? id,
  double width = 200.0,
  double height = 100.0,
  Color color = const Color(0xFFFFF59D), // Light yellow
}) {
  final node = CommentNode<T>(
    id: id ?? 'comment-${DateTime.now().millisecondsSinceEpoch}',
    position: position,
    text: text,
    data: data,
    width: width,
    height: height,
    color: color,
  );
  addNode(node);
  return node;
}