From 784f153b55c39838f90c7fb923d80857adf5e6b7 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 24 Dec 2020 14:13:29 +0800 Subject: [PATCH] add asCheckTag --- example/lib/example_tag.dart | 9 ++++++ lib/ansu_ui.dart | 2 ++ lib/tag/as_check_tag.dart | 54 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 lib/tag/as_check_tag.dart diff --git a/example/lib/example_tag.dart b/example/lib/example_tag.dart index b78c181..cde467a 100644 --- a/example/lib/example_tag.dart +++ b/example/lib/example_tag.dart @@ -10,6 +10,7 @@ class ExampleTag extends StatefulWidget { } class _ExampaleTagState extends State { + bool _checked = false; @override Widget build(BuildContext context) { return ASScaffold( @@ -56,6 +57,14 @@ class _ExampaleTagState extends State { title: Text('transport'), trailing: ASTag.transport('海运'), ), + ListTile( + onTap: () => setState(() => _checked = !_checked), + title: Text('ASCheckedTag'), + trailing: ASCheckTag( + checked: _checked, + text: 'TAG'.text, + ), + ), ], )); } diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index 032eba2..f52629c 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -53,6 +53,8 @@ export 'box/as_check_box.dart'; export 'pop_up_menu/pop_up_menu.dart'; export 'tag/as_tag.dart'; +export 'tag/as_check_tag.dart'; + export 'divider/as_divider.dart'; export 'text_field/as_search_text_field.dart'; export 'badge/as_badge.dart'; diff --git a/lib/tag/as_check_tag.dart b/lib/tag/as_check_tag.dart new file mode 100644 index 0000000..f296277 --- /dev/null +++ b/lib/tag/as_check_tag.dart @@ -0,0 +1,54 @@ +import 'package:ansu_ui/ansu_ui.dart'; +import 'package:flutter/material.dart'; +import 'package:ansu_ui/extension/num_extension.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class ASCheckTag extends StatelessWidget { + final bool checked; + final Widget text; + const ASCheckTag({ + Key key, + this.checked = false, + @required this.text, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + AnimatedContainer( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + height: 14.w, + width: 14.w, + decoration: BoxDecoration( + color: checked ? Color(0xFF00BF44) : Color(0xFFFF0000), + borderRadius: 7.radius, + ), + alignment: Alignment.center, + child: AnimatedSwitcher( + duration: Duration(milliseconds: 300), + switchInCurve: Curves.easeInOutCubic, + switchOutCurve: Curves.easeInOutCubic, + child: Icon( + checked ? Icons.check : Icons.clear, + key: ValueKey(checked), + size: 10.w, + color: kForegroundColor, + ), + ), + ), + 6.wb, + AnimatedDefaultTextStyle( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + style: TextStyle( + color: checked ? Color(0xFF00BF44) : Color(0xFFFF0000), + ), + child: text, + ), + ], + ); + } +}