From fc2c2d506cad8eac4abb2be11a0e4b08cfe657cd Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 26 Nov 2020 16:38:42 +0800 Subject: [PATCH 1/2] add as edit tile --- example/lib/example_listtile.dart | 5 +++ lib/ansu_ui.dart | 3 ++ lib/list_tile/as_edit_tile.dart | 64 +++++++++++++++++++++++++++++++ lib/list_tile/as_option_tile.dart | 29 ++++++++------ 4 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 lib/list_tile/as_edit_tile.dart diff --git a/example/lib/example_listtile.dart b/example/lib/example_listtile.dart index 9eeaa00..f1f8efe 100644 --- a/example/lib/example_listtile.dart +++ b/example/lib/example_listtile.dart @@ -50,6 +50,11 @@ class _ExampleListTileState extends State { ), ), ), + ASOptionTile.single( + item: ASEditTile( + title: Text('TEST'), + ), + ), ], ), ); diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index 4be49a2..a1e7b2c 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -14,8 +14,11 @@ export 'drawer/as_drawer.dart'; export 'pickers/as_date_picker.dart'; export 'pickers/as_picker_box.dart'; export 'dialog/as_dialog.dart'; + export 'list_tile/as_list_tile.dart'; export 'list_tile/as_option_tile.dart'; +export 'list_tile/as_edit_tile.dart'; + export 'tag/as_tag.dart'; export 'divider/as_divider.dart'; export 'text_field/as_search_text_field.dart'; diff --git a/lib/list_tile/as_edit_tile.dart b/lib/list_tile/as_edit_tile.dart new file mode 100644 index 0000000..751205e --- /dev/null +++ b/lib/list_tile/as_edit_tile.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; +import 'package:ansu_ui/ansu_ui.dart'; + +class ASEditTile extends StatefulWidget { + final Widget title; + final FocusNode node; + ASEditTile({Key key, this.title, this.node}) : super(key: key); + + @override + _ASEditTileState createState() => _ASEditTileState(); +} + +class _ASEditTileState extends State { + FocusNode _node; + @override + Widget build(BuildContext context) { + return InkWell( + onTap: () { + if (widget.node != null) { + widget.node?.requestFocus(); + } else { + _node?.requestFocus(); + } + }, + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: 46.w), + child: Row( + children: [ + 10.wb, + DefaultTextStyle( + style: TextStyle( + color: Colors.black.withOpacity(0.65), + fontSize: 14.sp, + ), + child: widget.title ?? Text(''), + ), + Expanded( + child: TextField( + focusNode: widget.node ?? _node, + textAlign: TextAlign.end, + style: TextStyle( + fontSize: 14.sp, + color: kTextColor, + fontWeight: FontWeight.bold, + ), + decoration: InputDecoration( + border: InputBorder.none, + isDense: true, + contentPadding: EdgeInsets.zero, + hintText: 'awd', + hintStyle: TextStyle( + color: kTextSubColor, + fontSize: 14.sp, + ), + ), + ), + ), + 10.wb, + ], + ), + ), + ); + } +} diff --git a/lib/list_tile/as_option_tile.dart b/lib/list_tile/as_option_tile.dart index 81ee28e..cd10fe6 100644 --- a/lib/list_tile/as_option_tile.dart +++ b/lib/list_tile/as_option_tile.dart @@ -7,10 +7,16 @@ 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); + + ///单个Widget + final Widget item; + ASOptionTile({Key key, this.items, this.item}) : super(key: key); + + ASOptionTile.single({Key key, @required this.item}) + : items = [], + super(key: key); int get length => items.length; @@ -21,15 +27,16 @@ class ASOptionTile extends StatelessWidget { 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(); - }), - ), + child: item ?? + Column( + children: List.generate(length * 2 - 1, (index) { + final displayIndex = index ~/ 2; + if (index.isEven) + return items[displayIndex]; + else + return ASDivider(indent: 14.w, endIndent: 14.w); + }), + ), ); } } From e68c86022764352aa3f3e4bc61f26758c5129f0d Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 26 Nov 2020 16:54:01 +0800 Subject: [PATCH 2/2] add as edit tile --- lib/list_tile/as_edit_tile.dart | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/list_tile/as_edit_tile.dart b/lib/list_tile/as_edit_tile.dart index 751205e..de09dfe 100644 --- a/lib/list_tile/as_edit_tile.dart +++ b/lib/list_tile/as_edit_tile.dart @@ -4,7 +4,15 @@ import 'package:ansu_ui/ansu_ui.dart'; class ASEditTile extends StatefulWidget { final Widget title; final FocusNode node; - ASEditTile({Key key, this.title, this.node}) : super(key: key); + final String hintText; + final TextEditingController controller; + ASEditTile({ + Key key, + this.title, + this.node, + this.hintText, + @required this.controller, + }) : super(key: key); @override _ASEditTileState createState() => _ASEditTileState(); @@ -14,7 +22,7 @@ class _ASEditTileState extends State { FocusNode _node; @override Widget build(BuildContext context) { - return InkWell( + return GestureDetector( onTap: () { if (widget.node != null) { widget.node?.requestFocus(); @@ -27,16 +35,19 @@ class _ASEditTileState extends State { child: Row( children: [ 10.wb, - DefaultTextStyle( - style: TextStyle( - color: Colors.black.withOpacity(0.65), - fontSize: 14.sp, + InkWell( + child: DefaultTextStyle( + style: TextStyle( + color: Colors.black.withOpacity(0.65), + fontSize: 14.sp, + ), + child: widget.title ?? Text(''), ), - child: widget.title ?? Text(''), ), Expanded( child: TextField( focusNode: widget.node ?? _node, + controller: widget.controller, textAlign: TextAlign.end, style: TextStyle( fontSize: 14.sp, @@ -47,7 +58,7 @@ class _ASEditTileState extends State { border: InputBorder.none, isDense: true, contentPadding: EdgeInsets.zero, - hintText: 'awd', + hintText: widget.hintText, hintStyle: TextStyle( color: kTextSubColor, fontSize: 14.sp,