码迷,mamicode.com
首页 > 其他好文 > 详细

flutter canvas 简单绘画直线

时间:2019-07-17 18:19:00      阅读:390      评论:0      收藏:0      [点我收藏+]

标签:gate   containe   isa   set   raw   child   draw   int()   extend   

1. 定义一个class

class MyPainter extends CustomPainter {
  Color lineColor;
  double width;

  MyPainter({this.lineColor, this.width});
  @override
  void paint(Canvas canvas, Size size) {
    Paint _paint = new Paint()
    ..color = Colors.blueAccent
    ..strokeCap = StrokeCap.round
    ..isAntiAlias = true
    ..strokeWidth = 5.0
    ..style = PaintingStyle.stroke;
    canvas.drawLine(Offset(20.0, 20.0), Offset(100.0, 100.0), _paint);

  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}

2. 使用

Container(
    child:CustomPaint(
        foregroundPainter: new MyPainter(
             lineColor: Colors.lightBlueAccent,
             width: 8.0,
       ),
    ),
),

flutter canvas 简单绘画直线

标签:gate   containe   isa   set   raw   child   draw   int()   extend   

原文地址:https://www.cnblogs.com/john-hwd/p/11202477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!