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.
42 lines
1.2 KiB
42 lines
1.2 KiB
import 'package:flutter/material.dart';
|
|
|
|
/// 虚线
|
|
class DottedLine extends StatelessWidget {
|
|
final double height;
|
|
final Color color;
|
|
final Axis direction;
|
|
|
|
const DottedLine({
|
|
this.height = 1,
|
|
this.color = Colors.black,
|
|
this.direction = Axis.horizontal,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
final boxWidth = direction == Axis.horizontal
|
|
? constraints.constrainWidth()
|
|
: constraints.constrainHeight();
|
|
final dashWidth = 10.0;
|
|
final dashHeight = height;
|
|
final dashCount = (boxWidth / (2 * dashWidth)).floor();
|
|
return Flex(
|
|
children: List.generate(dashCount, (_) {
|
|
return SizedBox(
|
|
width: direction == Axis.horizontal ? dashWidth : dashHeight,
|
|
height: direction == Axis.horizontal ? dashHeight : dashWidth,
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(color: color),
|
|
),
|
|
);
|
|
}),
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
direction: direction,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|