Flutter canvas,如何在子部件上绘制?

Flutter canvas, how to paint over the child widget?

我正在尝试像这样在子文本框小部件上绘制红点:

为此,我用 CustomPaint() 小部件包裹了子小部件:

 return CustomPaint(
      painter: DotsPainter(), //draws red dots based on child's size
      child: child, //textbox
    );

但结果是这样的:

如何让 CustomPainter“覆盖”它的子部件?

谢谢。

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.

(强调我的)

因此,如果您将画家移至 foregroundPainter,它应该可以正常工作:

return CustomPaint(
  foregroundPainter: DotsPainter(), //draws red dots based on child's size
  child: child, //textbox
);