基础组件库
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

44 rindas
1.2 KiB

  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. }