Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+0028 [数据] 如何获取一个Widget的坐标、所属矩形区域? #62

Open
toly1994328 opened this issue Sep 23, 2020 · 1 comment
Labels
point The point of Flutter

Comments

@toly1994328
Copy link
Owner

toly1994328 commented Sep 23, 2020

有时需要根据Widget的坐标进行相应处理,可以通过GlobalKeycurrentContext.findRenderObject()获取该组件的RenderBox,从而得到相关数据。

@toly1994328
Copy link
Owner Author

RenderBox renderBox = youKey.currentContext.findRenderObject();
var offsetGlobal = renderBox.localToGlobal(Offset.zero);
Rect globalRect = Rect.fromPoints(
    offsetGlobal,
    offsetGlobal.translate(
        renderBox.size.width, renderBox.size.height));

@toly1994328 toly1994328 added the point The point of Flutter label Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
point The point of Flutter
Projects
None yet
Development

No branches or pull requests

1 participant