getWidgetOffset static method

Offset? getWidgetOffset(
  1. GlobalKey<State<StatefulWidget>> key
)

Gets the offset of a widget identified by its GlobalKey.

Returns the offset of the widget on the screen.

Example:

Offset? offset = EaseSimulator.getWidgetOffset(key);
if (offset != null) {
  print("Widget Offset: $offset");
}

Implementation

static Offset? getWidgetOffset(GlobalKey key) {
  try {
    RenderBox renderBox = key.currentContext!.findRenderObject() as RenderBox;
    return renderBox.localToGlobal(Offset.zero);
  } catch (e) {
    print("Failed to get widget offset: $e");
    return null;
  }
}