美文网首页
flutter自绘组件

flutter自绘组件

作者: ChaosHeart | 来源:发表于2020-09-01 10:28 被阅读0次

1.自绘控件

CustomPaint({
    Key key,
    this.painter, //背景层
    Widget child, //中间层
    this.foregroundPainter, //前景层
    this.size = Size.zero, //绘制区域大小
    this.isComplex = false,
    this.willChange = false,
  })

2.自绘接口

//自定义自己的
class MyPainter extends CustomPainter {
  ///paint
  @override
  void paint(Canvas canvas, Size size) {
    //绘制内容(自己写的方法)
    _setPaint(canvas, size);
  }

  //在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
  ///shouldRepaint
  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
}

参考:
https://book.flutterchina.club/chapter10/custom_paint.html

相关文章

网友评论

      本文标题:flutter自绘组件

      本文链接:https://www.haomeiwen.com/subject/qrnmsktx.html