I'm working on drawing shapes and editing them using CustomPainr() and GestureDetector(). I've successfully drawn the shapes and now I'm going to select and drag the drawn shapes to move them.
I didn't understand much about implementing it yet, but dragging and moving the rectangle succeeded in the following way.
List<Rectangle>? _rects;
List<Line>? _lines;
GestureDetector(
onScaleStart: (details) {
RenderBox box = context.findRenderObject() as RenderBox;
Offset point = box.globalToLocal(details.focalPoint);
// check point on shape
final selectedRectIndex =
_rects!.lastIndexWhere((rect) => rect.rect!.contains(point));
}
// canvas
canvas.drawOval(shape.rect!, shape.paint);
canvas.drawLine(shape.p1!, shape.p2!, shape.paint);
The contents() could be used to determine if the offset was in a Rect() of rectangle. And the move was successful by updating points in onScaleUpdate().
Then, how do I check if the point I touched is in the Line shape? Is there a method for this, like "rect!.contains(point)"?
- And then I'm going to add this function, when the shape is selected like in the image below, there's a point at the vertex, and drag it to change the rotation or scale.
Can I get some advice to do this?
