findGlobalRect static method

Rect? findGlobalRect(
  1. GlobalKey<State<StatefulWidget>> key
)

Implementation

static Rect? findGlobalRect(GlobalKey key) {
  RenderBox renderObject =
      key.currentContext?.findRenderObject() as RenderBox;
  if (renderObject == null) {
    return null;
  }

  var globalOffset = renderObject.localToGlobal(Offset.zero);

  if (globalOffset == null) {
    return null;
  }

  var bounds = renderObject.paintBounds;
  bounds = bounds.translate(globalOffset.dx, globalOffset.dy);
  return bounds;
}