Skip to content

Commit

Permalink
TW-529: Support get current RelativeRect of widget
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Aug 29, 2023
1 parent 5cf50b7 commit 8d50088
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/utils/extension/build_context_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,23 @@ extension ContextExtensionss on BuildContext {

void pushChild(String path) =>
push('${GoRouterState.of(this).uri.path}/$path');

RelativeRect getCurrentRelativeRectOfWidget() {
final RenderBox button = findRenderObject()! as RenderBox;
final RenderBox overlay =
Navigator.of(this).overlay!.context.findRenderObject()! as RenderBox;
final Offset offset;
offset = Offset(0.0, button.size.height);
final RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints(
button.localToGlobal(offset, ancestor: overlay),
button.localToGlobal(
button.size.bottomRight(Offset.zero) + offset,
ancestor: overlay,
),
),
Offset.zero & overlay.size,
);
return position;
}
}

0 comments on commit 8d50088

Please sign in to comment.