0

OK so straight to the point in flutter in order to draw a line we have to define offset points and as a dummy i cant understand how they work. I know that the offset displaces the drawn line but how am I suppose to know what values should I pass. For example the code below :

'''canvas.drawLine(Offset(265, -120), Offset(size.width+60, size.width-280), paint1);
  canvas.drawLine(Offset(200, -80), Offset(size.width+60, size.width-160), paint2);
  canvas.drawLine(Offset(100, -40), Offset(size.width+60, size.width-40), paint3);
  canvas.drawLine(Offset(0, 0), Offset(size.width+60, size.width+80), paint4);'''

I do not understand where are these points located on the device screen , so my question is how to calculate these points?

1 Answers1

0

You can see Offset as points on a graph...Every widget has its own graph when created and it is always at position (0,0) which is the X-axis and Y-axis value this is written as Offset(0,0) or Offset.zero

So from Offset(0,0) to Offset(1,0) will give you a horizontal line because the value of the X-axis has changed but the value of the Y-axis remains the same

Conversely, Offset(0,0) to Offset(0,1) will give a vertical line because the value of the Y-axis changed from 0 to 1 and the value of the X-axis remains the same.

Knowing what values to put depends on your requirements.

Hope this helps you.

Josteve
  • 11,459
  • 1
  • 23
  • 35
  • 1
    one piece to remember... offset in the X direction goes from left to right as the numbers get bigger. offset in the Y direction goes TOP to BOTTOM as the numbers get bigger – William Terrill Mar 18 '20 at 18:11