If you want to add a Dashed Border in flutter? Use the below flutter example add a Dashed Border in your flutter application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import 'dart:math'; import 'package:flutter/material.dart'; class CircularBorder extends StatelessWidget { final Color color; final double size; final double width; final Widget icon; const CircularBorder({Key key, this.color = Colors.blue, this.size = 70, this.width = 7.0, this.icon}) : super(key: key); @override Widget build(BuildContext context) { return Container( height: size, width: size, alignment: Alignment.center, child: Stack( alignment: Alignment.center, children: <Widget>[ icon == null ? Container() : icon, CustomPaint( size: Size(size, size), foregroundPainter: new MyPainter( completeColor: color, width: width), ), ], ), ); } } class MyPainter extends CustomPainter { Color lineColor = Colors.transparent; Color completeColor; double width; MyPainter( { this.completeColor, this.width}); @override void paint(Canvas canvas, Size size) { Paint complete = new Paint() ..color = completeColor ..strokeCap = StrokeCap.round ..style = PaintingStyle.stroke ..strokeWidth = width; Offset center = new Offset(size.width / 2, size.height / 2); double radius = min(size.width / 2, size.height / 2); var percent = (size.width *0.001) / 2; double arcAngle = 2 * pi * percent; print("$radius - radius"); print("$arcAngle - arcAngle"); print("${radius / arcAngle} - divider"); for (var i = 0; i < 8; i++) { var init = (-pi / 2)*(i/2); canvas.drawArc(new Rect.fromCircle(center: center, radius: radius), init, arcAngle, false, complete); } } @override bool shouldRepaint(CustomPainter oldDelegate) { return true; } } |
Using:
1 2 3 4 5 6 | CircularBorder( width: 6, size: 55, color: Colors.grey, icon: Icon(Icons.access_alarm, color: Colors.grey), ), |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.