buildWidget method

  1. @override
Widget buildWidget(
  1. BuildContext context
)
override

Builds the visual representation of the annotation.

This method is called by the framework to render the annotation's content. Implement this to define how your custom annotation appears on the canvas.

The framework automatically wraps your widget with:

  • Positioning logic (using visualPosition)
  • Selection visual feedback
  • Theme-consistent borders and highlights

Example

@override
Widget buildWidget(BuildContext context) {
  return Container(
    width: size.width,
    height: size.height,
    decoration: BoxDecoration(
      color: Colors.blue,
      borderRadius: BorderRadius.circular(8),
    ),
    child: Center(child: Text('My Annotation')),
  );
}

Implementation

@override
Widget buildWidget(BuildContext context) {
  return Container(
    width: width,
    height: height,
    decoration: BoxDecoration(
      color: color.withValues(alpha: 0.9),
      borderRadius: BorderRadius.circular(8),
      boxShadow: [
        BoxShadow(
          color: Colors.black.withValues(alpha: 0.1),
          blurRadius: 4,
          offset: const Offset(0, 2),
        ),
      ],
    ),
    padding: const EdgeInsets.all(12),
    child: Text(
      text,
      style: Theme.of(context).textTheme.bodyMedium,
      overflow: TextOverflow.fade,
    ),
  );
}