From 3daa146ea9bb2b6d60f8a571aaa8547a534dcb96 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 26 Nov 2020 14:53:39 +0800 Subject: [PATCH] add OptionTile --- example/lib/example_listtile.dart | 16 +++- lib/ansu_ui.dart | 3 +- lib/extension/sizedbox_extension.dart | 2 + .../as_list_tile.dart} | 0 lib/list_tile/as_option_tile.dart | 80 +++++++++++++++++++ lib/text_field/as_search_text_field.dart | 2 +- 6 files changed, 99 insertions(+), 4 deletions(-) rename lib/{widget/as_listtile.dart => list_tile/as_list_tile.dart} (100%) create mode 100644 lib/list_tile/as_option_tile.dart diff --git a/example/lib/example_listtile.dart b/example/lib/example_listtile.dart index bfb4863..9eeaa00 100644 --- a/example/lib/example_listtile.dart +++ b/example/lib/example_listtile.dart @@ -1,6 +1,5 @@ import 'package:ansu_ui/ansu_ui.dart'; import 'package:ansu_ui/divider/as_divider.dart'; -import 'package:ansu_ui/widget/as_listtile.dart'; import 'package:flutter/material.dart'; class ExampleListTile extends StatefulWidget { @@ -17,7 +16,9 @@ class _ExampleListTileState extends State { title: 'ASListTile', body: ListView( children: [ - SizedBox(height: 8.w,), + SizedBox( + height: 8.w, + ), Container( color: Color(0xFFFFFFFF), padding: EdgeInsets.symmetric(horizontal: 8.w), @@ -38,6 +39,17 @@ class _ExampleListTileState extends State { ], ), ), + 20.hb, + ASOptionTile( + items: List.generate( + 3, + (index) => ASOptionTileItem( + leading: Icon(Icons.verified), + title: Text('Test'), + onPressed: () {}, + ), + ), + ), ], ), ); diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index 0d1b72d..4be49a2 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -14,7 +14,8 @@ export 'drawer/as_drawer.dart'; export 'pickers/as_date_picker.dart'; export 'pickers/as_picker_box.dart'; export 'dialog/as_dialog.dart'; -export 'widget/as_listtile.dart'; +export 'list_tile/as_list_tile.dart'; +export 'list_tile/as_option_tile.dart'; export 'tag/as_tag.dart'; export 'divider/as_divider.dart'; export 'text_field/as_search_text_field.dart'; diff --git a/lib/extension/sizedbox_extension.dart b/lib/extension/sizedbox_extension.dart index 9f2bff3..576d508 100644 --- a/lib/extension/sizedbox_extension.dart +++ b/lib/extension/sizedbox_extension.dart @@ -3,7 +3,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; extension SizedBoxExt on num { + ///获取宽 SizedBox Widget get wb => SizedBox(width: ScreenUtil().setWidth(this)); + ///获取高 SizedBox Widget get hb => SizedBox(height: ScreenUtil().setWidth(this)); } diff --git a/lib/widget/as_listtile.dart b/lib/list_tile/as_list_tile.dart similarity index 100% rename from lib/widget/as_listtile.dart rename to lib/list_tile/as_list_tile.dart diff --git a/lib/list_tile/as_option_tile.dart b/lib/list_tile/as_option_tile.dart new file mode 100644 index 0000000..81ee28e --- /dev/null +++ b/lib/list_tile/as_option_tile.dart @@ -0,0 +1,80 @@ +import 'package:ansu_ui/ansu_ui.dart'; +import 'package:ansu_ui/styles/as_colors.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:ansu_ui/extension/sizedbox_extension.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +///菜单按钮Tile +class ASOptionTile extends StatelessWidget { + + ///应使用 ASOptionTileItem + final List items; + const ASOptionTile({Key key, @required this.items}) : super(key: key); + + int get length => items.length; + + @override + Widget build(BuildContext context) { + return Material( + color: kForegroundColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5.w), + ), + child: Column( + children: List.generate(length * 2 - 1, (index) { + final displayIndex = index ~/ 2; + if (index.isEven) + return items[displayIndex]; + else + return ASDivider(); + }), + ), + ); + } +} + +class ASOptionTileItem extends StatelessWidget { + final Widget leading; + final Widget title; + final onPressed; + const ASOptionTileItem({ + Key key, + this.leading, + this.title, + this.onPressed, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onPressed, + borderRadius: BorderRadius.circular(5.w), + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: 46.w), + child: Row( + children: [ + 14.wb, + leading ?? SizedBox(), + leading != null ? 8.wb : 0.wb, + Expanded( + child: DefaultTextStyle( + style: TextStyle( + color: Colors.black.withOpacity(0.65), + fontSize: 14.sp, + ), + child: title, + ), + ), + 14.wb, + Icon( + CupertinoIcons.chevron_forward, + size: 16.w, + ), + 14.wb, + ], + ), + ), + ); + } +} diff --git a/lib/text_field/as_search_text_field.dart b/lib/text_field/as_search_text_field.dart index 909c1c1..31366fa 100644 --- a/lib/text_field/as_search_text_field.dart +++ b/lib/text_field/as_search_text_field.dart @@ -56,7 +56,7 @@ class ASSearchTextField extends StatefulWidget implements PreferredSizeWidget { _ASSearchTextFieldState createState() => _ASSearchTextFieldState(); @override - Size get preferredSize => Size.fromHeight(42.w); + Size get preferredSize => Size.fromHeight(42); } class _ASSearchTextFieldState extends State {