Skip to content

Instantly share code, notes, and snippets.

@bistole
Created March 17, 2021 20:18
Show Gist options
  • Save bistole/adf512d71bdf23fcbfc14dd4d7b01e6b to your computer and use it in GitHub Desktop.
Save bistole/adf512d71bdf23fcbfc14dd4d7b01e6b to your computer and use it in GitHub Desktop.
get rect from rendered widget
Rect getRectFromWidget(GlobalKey gKey) {
final keyContext = gKey.currentContext;
if (keyContext != null) {
final box = keyContext.findRenderObject() as RenderBox;
final offset = box.localToGlobal(Offset.zero);
final size = box.hasSize ? box.size : Size.zero;
return Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
}
return Rect.zero;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment