How to add line dash in Flutter

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

How to make a line dash in Flutter like this?

10条回答
  •  名媛妹妹
    2021-02-07 03:25

    Vertical dashed line:
    I modifed maksimr's example:

    class DashedLine extends StatelessWidget {
      final double height;
      final double heightContainer;
      final Color color;
    
      const DashedLine({this.height = 3, this.color = Colors.black, this.heightContainer = 70});
    
      @override
      Widget build(BuildContext context) {
        return Container(
          height: heightContainer,
          child: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
              final boxHeight = constraints.constrainHeight();
              final dashWidth = 10.0;
              final dashHeight = height;
              final dashCount = (boxHeight / (2 * dashHeight)).floor();
              return Flex(
                children: List.generate(dashCount, (_) {
                  return SizedBox(
                    width: dashWidth,
                    height: dashHeight,
                    child: DecoratedBox(
                      decoration: BoxDecoration(color: color),
                    ),
                  );
                }),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                direction: Axis.vertical,
              );
            },
          ),
        );
      }
    }
    

提交回复
热议问题