51 lines
1.4 KiB
Dart
Executable File
51 lines
1.4 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
|
|
class DashedLine extends StatelessWidget {
|
|
const DashedLine({
|
|
super.key,
|
|
this.thickness = 0.5,
|
|
this.color = Colors.black,
|
|
this.direction = Axis.horizontal,
|
|
this.gap = 2,
|
|
});
|
|
|
|
final double thickness;
|
|
final double gap;
|
|
final Color color;
|
|
final Axis direction;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final boxExtent = switch (direction) {
|
|
Axis.horizontal => constraints.constrainWidth(),
|
|
Axis.vertical => constraints.constrainHeight(),
|
|
};
|
|
final dashThickness = gap;
|
|
final dashCount = (boxExtent / (2 * dashThickness)).floor();
|
|
return Flex(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
direction: direction,
|
|
children: List.generate(
|
|
dashCount,
|
|
(_) => SizedBox.fromSize(
|
|
size: switch (direction) {
|
|
Axis.horizontal => Size(
|
|
dashThickness,
|
|
thickness,
|
|
),
|
|
Axis.vertical => Size(
|
|
thickness,
|
|
dashThickness,
|
|
),
|
|
},
|
|
child: ColoredBox(
|
|
color: color,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|