颤振中的全局位置和局部位置有什么区别? [英] What is the difference between globalposition and localposition in flutter?

查看:94
本文介绍了颤振中的全局位置和局部位置有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故,我获得了相同的值,我无法理解颤动中全局位置和局部位置之间的差异.

Somehow I'm getting same values for both, I'm not able to understand the difference between global and local position in flutter.

RenderBox getBox = context.findRenderObject();
Offset position = getBox.localToGlobal(Offset.zero);
var local = getBox.globalToLocal(update.globalPosition);

推荐答案

GlobalPosition是屏幕上某个点的坐标,以屏幕的左上角为原点.而LocalPosition是RenderBox内点的坐标,以RenderBox的左上角为原点.如果您获得相同的值,则仅表示您的RenderBox覆盖了整个屏幕.

GlobalPosition are the coordinate of a point on screen with the top-left corner of the screen as the origin. Whereas LocalPosition are the coordinates of a point inside a RenderBox with the top-left corner of the RenderBox as the origin. If you are getting the same value, then it just means that your RenderBox is covering the whole screen.

更准确地说,这仅意味着RenderBox左上角与屏幕左上角相同.

More precisely, it just means that your RenderBox top-left corner is the same as the screen top-left corner.

这篇关于颤振中的全局位置和局部位置有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆