From 95ad140480ea11516dae0a92f92e16f346f60bc8 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Thu, 29 Jul 2021 19:05:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=99=9A=E7=BA=BF=E5=88=86?= =?UTF-8?q?=E5=89=B2=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main_home.dart | 5 ++ example/lib/widgets/example_divider.dart | 60 ++++++++++++++++++++++++ lib/divider/as_dotted_divider.dart | 58 +++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 example/lib/widgets/example_divider.dart create mode 100644 lib/divider/as_dotted_divider.dart diff --git a/example/lib/main_home.dart b/example/lib/main_home.dart index 45cb367..6214ecc 100644 --- a/example/lib/main_home.dart +++ b/example/lib/main_home.dart @@ -2,6 +2,7 @@ import 'package:example/widgets/example_bottom_button.dart'; import 'package:example/widgets/example_box.dart'; import 'package:example/widgets/example_button.dart'; import 'package:example/widgets/example_dialog.dart'; +import 'package:example/widgets/example_divider.dart'; import 'package:example/widgets/example_drawer.dart'; import 'package:example/widgets/example_listtile.dart'; import 'package:example/widgets/example_numeric_button.dart'; @@ -109,6 +110,10 @@ class _MainHomeState extends State { title: 'Toast', onPressed: () => Get.to(ExampleToast()), ), + _innerButton( + title: 'Divider', + onPressed: () => Get.to(ExampleDivider()), + ), ], ); } diff --git a/example/lib/widgets/example_divider.dart b/example/lib/widgets/example_divider.dart new file mode 100644 index 0000000..b991a8c --- /dev/null +++ b/example/lib/widgets/example_divider.dart @@ -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 { + @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(), + ), + ], + ), + ), + ); + } +} diff --git a/lib/divider/as_dotted_divider.dart b/lib/divider/as_dotted_divider.dart new file mode 100644 index 0000000..2676be8 --- /dev/null +++ b/lib/divider/as_dotted_divider.dart @@ -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? dash; + final Color? color; + final double? dashWidth; + final double? strokeWidth; + const ASDottedDivider({ + required this.axis, + this.dash = const [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 [2, 1]; + + ASDottedDivider.vertical({ + this.dashWidth, + this.strokeWidth, + this.color = const Color(0xFFD8D8D8), + }) : this.axis = Axis.vertical, + this.dash = const [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)), + ))); + }); + } +}