[英]Flutter canvas, how to paint over the child widget?
I am trying to draw red dots over the child textbox widget like this:我正在尝试在子文本框小部件上绘制红点,如下所示:
For that, I wrapped the child widget with CustomPaint()
widget:为此,我用CustomPaint()
小部件包装了子小部件:
return CustomPaint(
painter: DotsPainter(), //draws red dots based on child's size
child: child, //textbox
);
But the result is this:但结果是这样的:
How to make CustomPainter "overlay" its child widget?如何使 CustomPainter “覆盖”其子小部件?
Thanks.谢谢。
The CustomPaint has 2 possible painters: CustomPaint 有 2 种可能的画家:
When asked to paint, CustomPaint first asks its painter to paint on the current canvas, then it paints its child, and then, after painting its child , it asks its foregroundPainter to paint.当被要求绘画时,CustomPaint首先要求它的画家在当前的canvas上绘画,然后它绘画它的孩子,然后,在绘画它的孩子之后,它要求它的foregroundPainter绘画。
(emphasis mine) (强调我的)
So if you move your painter to the foregroundPainter instead, it should work fine:因此,如果您将您的画家移动到foregroundPainter ,它应该可以正常工作:
return CustomPaint(
foregroundPainter: DotsPainter(), //draws red dots based on child's size
child: child, //textbox
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.