Skip to content

Commit

Permalink
DropdownMenu、Textarea 组件优化
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaikai committed Jul 9, 2024
1 parent 7cda1e8 commit 69e1aaf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -108,11 +109,15 @@ class TDDropdownPopup {

Widget _getPopup(TDDropdownMenuDirection value, TDDropdownItem? updateChild, Completer<void> 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,
Expand All @@ -126,68 +131,57 @@ class TDDropdownPopup {
initContentTop: _initContentTop,
reverseHeight: _overlay3Height,
closeCallback: _closeCallback,
onOpened:() {
onOpened: () {
completer.complete();
},
child: updateChild ?? child,
)),
]);
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TDTextarea extends StatefulWidget {
this.labelIcon,
this.labelWidth,
this.margin,
this.padding,
this.textareaDecoration,
this.bordered,
}) : super(key: key);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -384,7 +388,7 @@ class _TDTextareaState extends State<TDTextarea> {
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(
Expand Down

0 comments on commit 69e1aaf

Please sign in to comment.