CustomPaint有两个可能的绘制器:
当被要求绘制时,CustomPaint首先要求其 painter 在当前画布上进行绘制,然后绘制其子项,绘制完其子项之后,它请求其 foregroundPainter 进行绘制。
(强调是我的)
因此,如果将您的绘图器移至foregroundPainter ,则应该可以正常工作:
return CustomPaint(
foregroundPainter: DotsPainter(), //draws red dots based on child's size
child: child, //textbox
);