基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dotted_line.dart 1.2 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'package:flutter/material.dart';
  2. /// 虚线绘制
  3. class DottedLine extends StatelessWidget {
  4. final double height;
  5. final double width;
  6. final Color color;
  7. final Axis direction;
  8. const DottedLine({
  9. this.height = 1,
  10. this.width = 10,
  11. this.color = Colors.black,
  12. this.direction = Axis.horizontal,
  13. });
  14. @override
  15. Widget build(BuildContext context) {
  16. return LayoutBuilder(
  17. builder: (BuildContext context, BoxConstraints constraints) {
  18. final boxWidth = direction == Axis.horizontal
  19. ? constraints.constrainWidth()
  20. : constraints.constrainHeight();
  21. final dashWidth = width;
  22. final dashHeight = height;
  23. final dashCount = (boxWidth / (2 * dashWidth)).floor();
  24. return Flex(
  25. children: List.generate(dashCount, (_) {
  26. return SizedBox(
  27. width: direction == Axis.horizontal ? dashWidth : dashHeight,
  28. height: direction == Axis.horizontal ? dashHeight : dashWidth,
  29. child: DecoratedBox(
  30. decoration: BoxDecoration(color: color),
  31. ),
  32. );
  33. }),
  34. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  35. direction: direction,
  36. );
  37. },
  38. );
  39. }
  40. }