From 5e8f79c455767da9e0e2c19a9db6094d1a110db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Wed, 21 Sep 2022 11:40:51 +0800 Subject: [PATCH] add search textfield suffix --- example/pubspec.lock | 136 ++++++++++------------- lib/text_field/as_search_text_field.dart | 60 +++++----- pubspec.lock | 111 +++++++++--------- 3 files changed, 146 insertions(+), 161 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index af1cb3a..ce7f42a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -21,93 +21,86 @@ packages: dependency: "direct main" description: name: args - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.3.1" async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" auto_size_text_pk: dependency: transitive description: name: auto_size_text_pk - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "3.0.0" bot_toast: dependency: transitive description: name: bot_toast - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "4.0.1" + version: "4.0.3" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.3.1" cli_util: dependency: transitive description: name: cli_util - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.3.3" + version: "0.3.5" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.15.0" cross_file: dependency: transitive description: name: cross_file - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.3.1+4" + version: "0.3.3+2" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.5" expandable: dependency: transitive description: name: expandable - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "5.0.1" file: dependency: transitive description: name: file - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.4" flutter: dependency: "direct main" description: flutter @@ -117,9 +110,9 @@ packages: dependency: transitive description: name: flutter_easyrefresh - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "2.2.2" flutter_localizations: dependency: "direct main" description: flutter @@ -129,16 +122,16 @@ packages: dependency: transitive description: name: flutter_plugin_android_lifecycle - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.7" flutter_screenutil: dependency: transitive description: name: flutter_screenutil - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "5.0.0+2" + version: "5.5.4" flutter_web_plugins: dependency: transitive description: flutter @@ -148,107 +141,100 @@ packages: dependency: "direct main" description: name: get - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "4.3.8" + version: "4.6.5" glob: dependency: transitive description: name: glob - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.1.0" grinder: dependency: "direct main" description: name: grinder - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.9.0" + version: "0.9.1" http: dependency: transitive description: name: http - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.13.3" + version: "0.13.5" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" image_picker: dependency: transitive description: name: image_picker - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.7.5+4" image_picker_for_web: dependency: transitive description: name: image_picker_for_web - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.1.8" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.6.1" intl: dependency: transitive description: name: intl - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.17.0" js: dependency: transitive description: name: js - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.6.3" lpinyin: dependency: transitive description: name: lpinyin - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.0.3" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.11.1" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -258,51 +244,51 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.1" velocity_x: dependency: transitive description: name: velocity_x - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "3.3.0" + version: "3.5.1" vxstate: dependency: transitive description: name: vxstate - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=2.15.0 <3.0.0" + flutter: ">=2.8.0" diff --git a/lib/text_field/as_search_text_field.dart b/lib/text_field/as_search_text_field.dart index 7d7c18b..5f3dada 100644 --- a/lib/text_field/as_search_text_field.dart +++ b/lib/text_field/as_search_text_field.dart @@ -15,6 +15,7 @@ class ASSearchTextField extends StatefulWidget implements PreferredSizeWidget { this.onPressed, this.height, this.prefix, + this.suffix, }) : button = false, super(key: key); @@ -30,6 +31,7 @@ class ASSearchTextField extends StatefulWidget implements PreferredSizeWidget { this.onPressed, this.height, this.prefix, + this.suffix, }) : button = true, super(key: key); @@ -62,6 +64,9 @@ class ASSearchTextField extends StatefulWidget implements PreferredSizeWidget { ///搜索内容筛选 final Widget? prefix; + /// 后置widget 只有非button类型有效 + final Widget? suffix; + @override _ASSearchTextFieldState createState() => _ASSearchTextFieldState(); @@ -142,34 +147,35 @@ class _ASSearchTextFieldState extends State { cursorColor: kPrimaryColor, textInputAction: TextInputAction.search, decoration: InputDecoration( - fillColor: Color(0xFFF8F8F8), - filled: true, - hintText: widget.hintText, - hintStyle: TextStyle( - color: kTextSubColor, - fontSize: 14.sp, - ), - border: _border, - enabledBorder: _border, - focusedBorder: _border, - focusedErrorBorder: _border, - prefixIcon: Padding( - padding: EdgeInsets.only(left: 13.w, right: 8.w), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Icon( - Icons.search, - size: 16.w, - color: Colors.black, - ), - widget.prefix ?? SizedBox(), - ], + fillColor: Color(0xFFF8F8F8), + filled: true, + hintText: widget.hintText, + hintStyle: TextStyle( + color: kTextSubColor, + fontSize: 14.sp, ), - ), - prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0), - contentPadding: EdgeInsets.zero, - ), + border: _border, + enabledBorder: _border, + focusedBorder: _border, + focusedErrorBorder: _border, + prefixIcon: Padding( + padding: EdgeInsets.only(left: 13.w, right: 8.w), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.search, + size: 16.w, + color: Colors.black, + ), + widget.prefix ?? SizedBox(), + ], + ), + ), + prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0), + contentPadding: EdgeInsets.zero, + suffix: widget.suffix, + suffixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0)), ), ); } diff --git a/pubspec.lock b/pubspec.lock index 321e64b..3740f7a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,77 +14,77 @@ packages: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.8.2" auto_size_text_pk: dependency: "direct main" description: name: auto_size_text_pk - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "3.0.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" bot_toast: dependency: "direct main" description: name: bot_toast - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "4.0.1" + version: "4.0.3" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.1" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.15.0" cross_file: dependency: transitive description: name: cross_file - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.3.1+5" + version: "0.3.3+2" expandable: dependency: "direct main" description: name: expandable - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "5.0.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" flutter: @@ -96,23 +96,23 @@ packages: dependency: "direct main" description: name: flutter_easyrefresh - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "2.2.2" flutter_plugin_android_lifecycle: dependency: transitive description: name: flutter_plugin_android_lifecycle - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.7" flutter_screenutil: dependency: "direct main" description: name: flutter_screenutil - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "5.0.0+2" + version: "5.5.4" flutter_test: dependency: "direct dev" description: flutter @@ -127,100 +127,93 @@ packages: dependency: "direct main" description: name: get - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "4.3.8" + version: "4.6.5" http: dependency: transitive description: name: http - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.13.3" + version: "0.13.5" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" image_picker: dependency: "direct main" description: name: image_picker - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.7.5+4" image_picker_for_web: dependency: transitive description: name: image_picker_for_web - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.1.8" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.6.1" intl: dependency: transitive description: name: intl - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.17.0" js: dependency: transitive description: name: js - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.6.3" lpinyin: dependency: "direct main" description: name: lpinyin - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.0.3" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.12.11" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.11.1" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -230,72 +223,72 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.4.3" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.1" velocity_x: dependency: "direct main" description: name: velocity_x - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "3.3.0" + version: "3.5.1" vxstate: dependency: transitive description: name: vxstate - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=2.15.0 <3.0.0" + flutter: ">=2.8.0"