From 9e9eb603b197e1c4dee49afe2974996232f34d29 Mon Sep 17 00:00:00 2001 From: kalifun Date: Thu, 23 Dec 2021 15:19:09 +0800 Subject: [PATCH] :art: BrnSearchText BrnSearchText --- .../components/sugsearch/brn_search_text.dart | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/src/components/sugsearch/brn_search_text.dart b/lib/src/components/sugsearch/brn_search_text.dart index 9fde0397..98656f3c 100644 --- a/lib/src/components/sugsearch/brn_search_text.dart +++ b/lib/src/components/sugsearch/brn_search_text.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:bruno/src/constants/brn_asset_constants.dart'; import 'package:bruno/src/constants/brn_strings_constants.dart'; @@ -19,16 +19,16 @@ typedef BrnOnTextClear = bool Function(); /// 基本IOS风格搜索框, 提供输入回调 class BrnSearchText extends StatefulWidget { /// 提示语 - final String hintText; + final String? hintText; /// 提示语样式 - final TextStyle hintStyle; + final TextStyle? hintStyle; /// 输入框样式 - final TextStyle textStyle; + final TextStyle? textStyle; /// 用于设置搜索框前端的 Icon - final Widget prefixIcon; + final Widget? prefixIcon; /// 包裹搜索框的容器背景色 final Color outSideColor; @@ -40,7 +40,7 @@ class BrnSearchText extends StatefulWidget { final int maxLines; /// 最大输入长度 - final int maxLength; + final int? maxLength; /// 输入框最大高度,默认 60 final double maxHeight; @@ -49,44 +49,44 @@ class BrnSearchText extends StatefulWidget { final EdgeInsets innerPadding; ///普通状态的 border - final BoxBorder normalBorder; + final BoxBorder? normalBorder; /// 激活状态的 Border, 默认和 border 一致 - final BoxBorder activeBorder; + final BoxBorder? activeBorder; /// 输入框圆角 final BorderRadius borderRadius; /// 右侧操作 widget - final Widget action; + final Widget? action; /// 是否自动获取焦点 final bool autoFocus; /// 用于控制键盘动作 - final TextInputAction textInputAction; - final TextEditingController controller; - final FocusNode focusNode; + final TextInputAction? textInputAction; + final TextEditingController? controller; + final FocusNode? focusNode; /// 文本变化的回调 - final BrnOnSearchTextChange onTextChange; + final BrnOnSearchTextChange? onTextChange; /// 提交文本时的回调 - final BrnOnCommit onTextCommit; + final BrnOnCommit? onTextCommit; /// 右侧 action 区域点击的回调 - final VoidCallback onActionTap; + final VoidCallback? onActionTap; /// 清除按钮的回调 如果用户设置了该属性 /// 如果返回值为true,表明用户想要拦截,则不会走默认的清除行为 /// 如果返回值为false,表明用户不想要拦截,在执行了用户的行为之后,还会走默认的行为 - final BrnOnTextClear onTextClear; + final BrnOnTextClear? onTextClear; /// 用于控制清除 Icon 和右侧 Action 的显示与隐藏。等其他复杂的操作。 - final BrnSearchTextController searchController; + final BrnSearchTextController? searchController; const BrnSearchText({ - Key key, + Key? key, this.searchController, this.controller, this.maxLines = 1, @@ -120,12 +120,12 @@ class BrnSearchText extends StatefulWidget { } class _SearchTextState extends State { - FocusNode focusNode; - TextEditingController textEditingController; - BoxBorder border; - BrnSearchTextController searchTextController; + FocusNode? focusNode; + TextEditingController? textEditingController; + BoxBorder? border; + BrnSearchTextController? searchTextController; - BrnSearchTextController tmpController; + BrnSearchTextController? tmpController; @override void initState() { @@ -135,7 +135,7 @@ class _SearchTextState extends State { tmpController = BrnSearchTextController(); } searchTextController = widget.searchController ?? tmpController; - searchTextController.addListener(() { + searchTextController!.addListener(() { if (mounted) { setState(() {}); } @@ -148,7 +148,7 @@ class _SearchTextState extends State { color: widget.innerColor, ); - focusNode.addListener(_handleFocusNodeChangeListenerTick); + focusNode!.addListener(_handleFocusNodeChangeListenerTick); } @override @@ -156,12 +156,12 @@ class _SearchTextState extends State { // TODO: implement dispose super.dispose(); tmpController?.dispose(); - focusNode.removeListener(_handleFocusNodeChangeListenerTick); + focusNode!.removeListener(_handleFocusNodeChangeListenerTick); } /// 焦点状态回到,用于刷新当前 UI void _handleFocusNodeChangeListenerTick() { - if (focusNode.hasFocus) { + if (focusNode!.hasFocus) { border = widget.activeBorder ?? border; } else { border = widget.normalBorder ?? border; @@ -216,7 +216,7 @@ class _SearchTextState extends State { // 光标颜色属性,绘制光标时使用的颜色。 cursorColor: BrnThemeConfigurator.instance .getConfig() - .commonConfig + .commonConfig! .brandPrimary, // 光标宽度属性,光标的厚度,默认是2.0。 cursorWidth: 2.0, @@ -226,7 +226,7 @@ class _SearchTextState extends State { textBaseline: TextBaseline.alphabetic, color: BrnThemeConfigurator.instance .getConfig() - .commonConfig + .commonConfig! .colorTextBase, fontSize: 16), // 装饰(`decoration`)属性,在文本字段周围显示的装饰。 @@ -256,34 +256,34 @@ class _SearchTextState extends State { // 在改变属性,当正在编辑的文本发生更改时调用。 onChanged: (content) { if (widget.onTextChange != null) { - widget.onTextChange(content); + widget.onTextChange!(content); } setState(() {}); }, onSubmitted: (content) { if (widget.onTextCommit != null) { - widget.onTextCommit(content); + widget.onTextCommit!(content); } }), ), Visibility( - visible: searchTextController.isClearShow, + visible: searchTextController!.isClearShow, child: GestureDetector( onTap: () { if (widget.onTextClear != null) { - bool isIntercept = widget.onTextClear() ?? false; + bool isIntercept = widget.onTextClear!() ?? false; if (isIntercept) return; } - textEditingController.clear(); + textEditingController!.clear(); if (this.widget.onTextChange != null) { this .widget - .onTextChange(textEditingController.value.text); + .onTextChange!(textEditingController!.value.text); } setState(() {}); }, child: Visibility( - visible: textEditingController.text.isNotEmpty, + visible: textEditingController!.text.isNotEmpty, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 12.0), @@ -299,12 +299,12 @@ class _SearchTextState extends State { ), ), Visibility( - visible: searchTextController.isActionShow, + visible: searchTextController!.isActionShow, child: widget.action ?? GestureDetector( onTap: () { if (widget.onActionTap != null) { - widget.onActionTap(); + widget.onActionTap!(); } }, child: Container( @@ -314,7 +314,7 @@ class _SearchTextState extends State { style: TextStyle( color: BrnThemeConfigurator.instance .getConfig() - .commonConfig + .commonConfig! .colorTextBase, fontSize: 16, height: 1),