gpt4 book ai didi

flutter Canvas ,如何在子小部件上绘画?

转载 作者:行者123 更新时间:2023-12-04 08:15:19 26 4
gpt4 key购买 nike

我试图在子文本框小部件上绘制红点,如下所示:
enter image description here
为此,我用 CustomPaint() 包裹了子小部件。小部件:

 return CustomPaint(
painter: DotsPainter(), //draws red dots based on child's size
child: child, //textbox
);
但结果是这样的:
enter image description here
如何使 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
);

关于 flutter Canvas ,如何在子小部件上绘画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65732865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com