How to add line dash in Flutter

前端 未结 10 1020
清歌不尽
清歌不尽 2021-02-07 02:54

How to make a line dash in Flutter like this?

10条回答
  •  攒了一身酷
    2021-02-07 03:08

    class DashedLinePainter extends CustomPainter {
      @override
      void paint(Canvas canvas, Size size) {
        double dashWidth = 9, dashSpace = 5, startX = 0;
        final paint = Paint()
          ..color = Colors.grey
          ..strokeWidth = 1;
        while (startX < size.width) {
          canvas.drawLine(Offset(startX, 0), Offset(startX + dashWidth, 0), paint);
          startX += dashWidth + dashSpace;
        }
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) => false;
    }
    

提交回复
热议问题