getLocalRect method
Get a widget's local bounds (relative to the Flutter view).
Returns null if the widget is not mounted or has no render box.
Implementation
Rect? getLocalRect(GlobalKey key) {
final renderBox = key.currentContext?.findRenderObject() as RenderBox?;
if (renderBox == null || !renderBox.hasSize) return null;
final position = renderBox.localToGlobal(Offset.zero);
final size = renderBox.size;
return Rect.fromLTWH(position.dx, position.dy, size.width, size.height);
}