parent
264fb000b3
commit
95ad140480
@ -0,0 +1,60 @@
|
||||
import 'package:ansu_ui/ansu_ui.dart';
|
||||
import 'package:ansu_ui/divider/as_dotted_divider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ExampleDivider extends StatefulWidget {
|
||||
ExampleDivider({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ExampleDividerState createState() => _ExampleDividerState();
|
||||
}
|
||||
|
||||
class _ExampleDividerState extends State<ExampleDivider> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ASScaffold(
|
||||
title: '分割线',
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 50.w,
|
||||
color: Colors.red,
|
||||
child: 'ASDivider'.text.make(),
|
||||
),
|
||||
ASDivider(color: Colors.black,),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
height: 50.w,
|
||||
color: Colors.red,
|
||||
).expand(),
|
||||
ASVDivider(),
|
||||
Container(
|
||||
height: 50.w,
|
||||
color: Colors.red,
|
||||
).expand(),
|
||||
],
|
||||
),
|
||||
ASDivider(),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 50.w,
|
||||
color: Colors.red,
|
||||
child: 'ASDottedDivider'.text.make(),
|
||||
),
|
||||
ASDottedDivider.horizontal(color: Colors.black,),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 50.w,
|
||||
color: Colors.red,
|
||||
child: 'ASDottedDivider'.text.make(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class ASDottedDivider extends StatelessWidget {
|
||||
final Axis axis;
|
||||
final List<int>? dash;
|
||||
final Color? color;
|
||||
final double? dashWidth;
|
||||
final double? strokeWidth;
|
||||
const ASDottedDivider({
|
||||
required this.axis,
|
||||
this.dash = const <int>[2, 1],
|
||||
this.color = const Color(0xFFD8D8D8),
|
||||
this.dashWidth,
|
||||
this.strokeWidth,
|
||||
});
|
||||
|
||||
ASDottedDivider.horizontal({
|
||||
this.dashWidth,
|
||||
this.strokeWidth,
|
||||
this.color = const Color(0xFFD8D8D8),
|
||||
}) : this.axis = Axis.horizontal,
|
||||
this.dash = const <int>[2, 1];
|
||||
|
||||
ASDottedDivider.vertical({
|
||||
this.dashWidth,
|
||||
this.strokeWidth,
|
||||
this.color = const Color(0xFFD8D8D8),
|
||||
}) : this.axis = Axis.vertical,
|
||||
this.dash = const <int>[2, 1];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(builder: (context, boxConstraints) {
|
||||
final boxWidth = this.axis == Axis.horizontal
|
||||
? boxConstraints.constrainWidth()
|
||||
: boxConstraints.constrainHeight();
|
||||
final _dashWidth = dashWidth ?? 10.w;
|
||||
final _dashPattern = (1 + dash![1] / dash![0]);
|
||||
final int count = (boxWidth / (_dashWidth * _dashPattern)).floor();
|
||||
return Flex(
|
||||
direction: axis,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(
|
||||
count,
|
||||
(_) => SizedBox(
|
||||
width: this.axis == Axis.horizontal
|
||||
? _dashWidth
|
||||
: strokeWidth ?? 1.w,
|
||||
height: this.axis == Axis.horizontal
|
||||
? strokeWidth ?? 1.w
|
||||
: _dashWidth,
|
||||
child:
|
||||
DecoratedBox(decoration: BoxDecoration(color: color)),
|
||||
)));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue