Flutter-虚线

542 阅读1分钟

Flutter-虚线

  1. 可以自定义虚线的方向,虚线密度,虚线颜色。仅做学习记录
class MJYDashLine extends StatelessWidget{
  final Axis axis;
  final double dashedWidth;
  final double dashedHeight ;
  final int count;
  final Color color;
  MJYDashLine({
    this.axis = Axis.horizontal,
    this.dashedHeight = 1,
    this.dashedWidth = 1,
    this.count = 10,
    this.color = Colors.red
});
  @override
  Widget build(BuildContext context) {
   return Flex(
     direction: axis,
     mainAxisAlignment: MainAxisAlignment.spaceBetween,
     children: List.generate(count, (_){
       return SizedBox(
         width: dashedWidth,
         height: dashedHeight,
         child: DecoratedBox(
          decoration: BoxDecoration(color: color),
         ),
       );
     }),
   );
  }
​
}
​

案例效果:

image-20221014114914615