Flutter畫圖

畫筆

p = Paint()
  ..color = Colors.orange // 畫筆的顏色
  ..strokeWidth = 2.0 // 線的寬度
  ..style = PaintingStyle.stroke // fill: 填充, stroke: 空心
  ..strokeCap = StrokeCap.butt // 轉(zhuǎn)折處的處理
  ..blendMode = BlendMode.dstIn; // 重疊處的處理模式,clear,src, dst, srcIn,dstIn等等。

Demo

樣式示例圖


image.png
class MyCirclePainterPaintModel {
  Color color; //畫筆色
  double progress; //進(jìn)度 1為全部

  MyCirclePainterPaintModel ({
    this.color,
    this.progress,
  });
}

class MyCirclePainter extends CustomPainter {
  double radius; //半徑
  double strokeWidth; //畫筆寬度
  Color bgColor; //底部背景色
  List <MyCirclePainterPaintModel> paints;
  MyCirclePainter ({
    this.radius = 50.0,
    this.strokeWidth = 12.0,
    this.bgColor =  Colors.grey,
    this.paints,
});

  @override
  void paint(Canvas canvas, Size size) {
    Offset offset = Offset(size.width*0.5, size.height * 0.5);
    var paint = Paint()
      ..color = Colors.grey
      ..style = PaintingStyle.stroke
      ..strokeWidth = strokeWidth;
    canvas.drawCircle(offset, radius, paint);
    if (paints != null && paints.length > 0) {
      double initSweepAngle = -90 * pi / 180; //初始開始角度
      for (var mPaint in paints) {
        var paint = Paint();
        paint
          ..color = mPaint.color
          ..strokeWidth = strokeWidth
          ..style = PaintingStyle.stroke
          ..strokeCap = StrokeCap.round;
        Rect rect = Rect.fromCenter(center: offset, width: radius * 2, height: radius * 2);
        double sweepAngle = mPaint.progress * 360; //完成角度
        double radian = sweepAngle * pi / 180;
        canvas.drawArc(rect, initSweepAngle, radian, false, paint);
        initSweepAngle += radian;
      }
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }

}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容