본문 바로가기
Mobile APP/Flutter

[Flutter] dashed line 그리기

by 흐암졸령 2023. 2. 15.
반응형

해결 방법

 dash 된 부분만 Line 을 그리는 방법으로 하였다.

void paintDashedLine(Canvas canvas, Size size) {
    Paint standardPaint = Paint()
      ..color = Colors.grey
      ..strokeWidth = 1;

    const int dashWidth = 4;
    const int dashSpace = 4;
    double startX = 0;
    double y = 20;

    while (startX < size.width) {
      canvas.drawLine(Offset(startX, y), Offset(startX + dashWidth, y), standardPaint);
      startX += dashWidth + dashSpace;
    }
  }

 

 

실행 결과

 

Reference

 

Flutter - How to draw dashed line on Canvas - Coflutter

Learn how to draw dashed line in Flutter using Canvas and CustomPaint.

coflutter.com

 

반응형

댓글