我正在制作一种绘画应用程序,让您在背景图像上绘画。有一些工具,比如笔,然后是橡皮擦。理想情况下,我们只在背景颜色上绘画,但它是一个图像。当我们在屏幕上平移时,我们的想法是删除手指下的点,但偏移量和本地位置不匹配(它们就像 40(单位?)关闭)。
onPanUpdate: (DragUpdateDetails details) {
//Adds the point you are tapping on to the '_points' list as Offset(x,y). Later we draw those points.
if (tool == 'pen') {
RenderBox object = context.findRenderObject();
Offset _localPosition =
object.globalToLocal(details.globalPosition);
_points = List.from(_points)..add(_localPosition);
} else if (tool == 'eraser') {
RenderBox object = context.findRenderObject();
Offset _localPosition =
object.globalToLocal(details.globalPosition);
_points = List.from(_points)
..removeWhere(
(offset) {
if (offset == null) return false;
if (offset.dx.round() == _localPosition.dx.round() &&
offset.dy.round() == _localPosition.dy.round()) {
return true;
}
return false;
},
);
//This part is not working.
}
setState(() {});
},
如果我可以使用另一种方法,那就太好了,但我现在还看不到。