Reputation: 7973
Although I know their uses and properties but sometimes I found it hard to tell the difference between Offset
and Alignment
as both of them represents a point in x-axis
and y-axis
Upvotes: 6
Views: 2088
Reputation: 166
For others out there: According to https://api.flutter.dev/flutter/painting/Alignment-class.html, The equation for alignment to offset is:
offsetX = alignmentX * width/2 + width/2
offsetY = alignmentY * height/2 + height/2
So using some algebra, to go the other way and convert an offset to an alignment is:
alignmentX = (offsetX - width/2)/(width/2)
alignmentY = (offsetY - height/2)/(height/2)
Where width and height is the width/height of the parent the offset is based on (like the window/screen if using global coordinates)
Upvotes: 4