From 69e1aafca401922a60ca0fd265e9d2e2930cbff8 Mon Sep 17 00:00:00 2001 From: hkaikai <617760820@qq.com> Date: Tue, 9 Jul 2024 10:15:45 +0800 Subject: [PATCH] =?UTF-8?q?DropdownMenu=E3=80=81Textarea=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dropdown_menu/td_dropdown_popup.dart | 88 +++++++++---------- .../src/components/textarea/td_textarea.dart | 8 +- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_popup.dart b/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_popup.dart index af9851238..467c3bf30 100644 --- a/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_popup.dart +++ b/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_popup.dart @@ -94,8 +94,9 @@ class TDDropdownPopup { return _directionListenable.value == TDDropdownPopupDirection.auto ? ValueListenableBuilder( valueListenable: _directionListenable, - builder: (context, value, child) => - value == TDDropdownPopupDirection.auto ? child! : _getPopup(value, updateChild, completer), // 每次重新渲染item,更新高度 + builder: (context, value, child) => value == TDDropdownPopupDirection.auto + ? child! + : _getPopup(value, updateChild, completer), // 每次重新渲染item,更新高度 child: _getPopup(TDDropdownPopupDirection.down, updateChild, completer), ) : _getPopup(_directionListenable.value, updateChild, completer); @@ -108,11 +109,15 @@ class TDDropdownPopup { Widget _getPopup(TDDropdownMenuDirection value, TDDropdownItem? updateChild, Completer completer) { _init(value); + final barrier = GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: _overlayClick, + ); return Stack(children: [ if (_directionListenable.value != TDDropdownPopupDirection.auto) ...[ - _getOverlay1(), + _getOverlay1(barrier), _getOverlay2(), - _getOverlay3(), + _getOverlay3(barrier), ], TDDropdownInherited( popupState: this, @@ -126,7 +131,7 @@ class TDDropdownPopup { initContentTop: _initContentTop, reverseHeight: _overlay3Height, closeCallback: _closeCallback, - onOpened:() { + onOpened: () { completer.complete(); }, child: updateChild ?? child, @@ -134,60 +139,49 @@ class TDDropdownPopup { ]); } - Widget _getOverlay1() { - return showOverlay == true - ? Positioned( - top: _overlay1Top, - bottom: _overlay1Bottom, - left: 0, - right: 0, - child: ValueListenableBuilder( + Widget _getOverlay1(Widget barrier) { + return Positioned( + top: _overlay1Top, + bottom: _overlay1Bottom, + left: 0, + right: 0, + child: showOverlay == true + ? ValueListenableBuilder( builder: (BuildContext context, value, Widget? child) { return AnimatedContainer( color: value ? Colors.black54 : Colors.black54.withAlpha(0), duration: _duration, - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: _overlayClick, - ), + child: barrier, ); }, valueListenable: _colorAlphaListenable, - ), - ) - : const SizedBox.shrink(); + ) + : barrier, + ); } Widget _getOverlay2() { - return showOverlay == true - ? Positioned( - top: _overlay2Top, - bottom: _overlay2Bottom, - left: 0, - right: 0, - child: GestureDetector( - onVerticalDragUpdate: (details) {}, - onHorizontalDragUpdate: (details) {}, - behavior: HitTestBehavior.translucent, - child: const SizedBox(), - ), - ) - : const SizedBox.shrink(); + return Positioned( + top: _overlay2Top, + bottom: _overlay2Bottom, + left: 0, + right: 0, + child: GestureDetector( + onVerticalDragUpdate: (details) {}, + onHorizontalDragUpdate: (details) {}, + behavior: HitTestBehavior.translucent, + ), + ); } - Widget _getOverlay3() { - return showOverlay == true - ? Positioned( - top: _overlay3Top, - bottom: _overlay3Bottom, - left: 0, - right: 0, - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: _overlayClick, - ), - ) - : const SizedBox.shrink(); + Widget _getOverlay3(Widget barrier) { + return Positioned( + top: _overlay3Top, + bottom: _overlay3Bottom, + left: 0, + right: 0, + child: barrier, + ); } void _overlayClick() { diff --git a/tdesign-component/lib/src/components/textarea/td_textarea.dart b/tdesign-component/lib/src/components/textarea/td_textarea.dart index fd28b3db8..183c29568 100644 --- a/tdesign-component/lib/src/components/textarea/td_textarea.dart +++ b/tdesign-component/lib/src/components/textarea/td_textarea.dart @@ -55,6 +55,7 @@ class TDTextarea extends StatefulWidget { this.labelIcon, this.labelWidth, this.margin, + this.padding, this.textareaDecoration, this.bordered, }) : super(key: key); @@ -167,12 +168,15 @@ class TDTextarea extends StatefulWidget { /// 标题输入框布局方式。可选项:vertical/horizontal final TDTextareaLayout? layout; - /// 是否自动增高,值为 autosize 时,maxLines 不生效 + /// 是否自动增高,值为 true 时,[maxLines]不生效 final bool? autosize; /// 外边距 final EdgeInsetsGeometry? margin; + /// 内边距 + final EdgeInsetsGeometry? padding; + /// 是否显示外边框 final bool? bordered; @@ -384,7 +388,7 @@ class _TDTextareaState extends State { width: widget.width, color: widget.decoration != null ? null : (widget.backgroundColor ?? Colors.white), decoration: widget.decoration, - padding: EdgeInsets.all(padding), + padding: widget.padding ?? EdgeInsets.all(padding), margin: widget.margin, child: isHorizontal ? Row(