What is the difference between globalposition and localposition in flutter?

1,496

GlobalPosition is the coordinate of a point on-screen with the top-left corner of the screen as the origin. Whereas LocalPosition is 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, it means that your RenderBox top-left corner is the same as the screen top-left corner.

Share:
1,496
Manoj Perumarath
Author by

Manoj Perumarath

ചവറു പോലെ എഴുതുന്നത് എനിക്ക് ഇഷ്ടമല്ല ! Hey there, if you have found my answers helpful you can buy me a coffee! Currently, Senior Mobile Developer at Emvigo Technologies, Kaloor, Ernakulam, Kerala.

Updated on December 10, 2022

Comments

  • Manoj Perumarath
    Manoj Perumarath over 1 year

    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);
    
  • MarcG
    MarcG about 5 years
    More precisely, it just means that your RenderBox top-left corner is the same as the screen top-left corner.
  • Ryosuke
    Ryosuke about 5 years
    @MarcG yeah that sounds more accurate.
  • genericUser
    genericUser over 2 years
    remove that line "If you are getting the same value, then it just means that your RenderBox is covering the whole screen", it's wrong