CustomPaint组件属性

6 min read
const CustomPaint({
  Key? key,
  this.painter,
  this.foregroundPainter,
  this.size = Size.zero,
  this.isComplex = false,
  this.willChange = false,
  Widget? child,
})
  • painter:绘制的对象,是一个CustomPainter。它的绘制是在child之前。如果设置了child,该painter绘制的内容会被覆盖。
  • foregroundPainter:绘制的对象,是一个CustomPainter。它的绘制是在child之后。如果设置了child,该painter绘制的内容会覆盖child。
  • size: 画板大小,如果定义了child,则会以child的尺寸为准
  • isComplex: 默认值是false,定义绘制内容是否复杂,如果为true,会对canvas的绘制进行一些必要的缓存来优化性能
  • willChange: 默认值是false,配合isComplex使用,控制组件是否在下一帧需要重绘
  • child: 子节点,可以不设置