How to draw a horizontal dotted line in flutter?

This Errors is posted by seven.srikanth at 5/17/2020 4:35:09 AM



As of now, there is no default dotted borderline support in flutter. If there is one, it would have been easy to draw a dotted line using that functionality. 
Dotted line reference below,
So, here I'm sharing the class for drawing a horizontal dotted line. 



class DrawDottedhorizontalline extends CustomPainter {
  Paint _paint;
  DrawDottedhorizontalline() {
    _paint = Paint()
      ..color = Colors.black
      ..strokeWidth = 2
      ..strokeCap = StrokeCap.round;
  }
  @override
  void paint(Canvas canvas, Size size) {
    for(double i = -300; i < 300; i = i + 15){
      if(i% 3 == 0)
      canvas.drawLine(Offset(i, 0.0), Offset(i+10, 0.0), _paint);
    }
  }
  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}
Here is how you call it.

Container(
   color: Colors.white,
   height: 40.0,
   child: Center(child:
   CustomPaint(painter: DrawDottedhorizontalline()),           
),), ),
Hope this helps.  
Thanks,
Srikanth

Tags:








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com