getPointInWidget method

Offset? getPointInWidget(
  1. GlobalKey<State<StatefulWidget>> key,
  2. Offset localOffset, {
  3. ScreenRect? windowBounds,
})

Get the screen position of a point within a widget.

key - GlobalKey attached to the widget. localOffset - Position within the widget (0,0 = top-left). windowBounds - Optional override for the palette's window bounds.

Useful for getting the position of a text caret within a text field.

Implementation

Offset? getPointInWidget(
  GlobalKey key,
  Offset localOffset, {
  ScreenRect? windowBounds,
}) {
  final bounds = windowBounds ?? this.windowBounds;
  if (bounds == null) return null;

  final widgetLocalRect = getLocalRect(key);
  if (widgetLocalRect == null) return null;

  // The point in palette-local coordinates
  final pointInPalette = widgetLocalRect.topLeft + localOffset;

  // Convert to screen coordinates
  return bounds.localToScreen(pointInPalette);
}