diff --git a/tdesign-component/lib/src/components/notice_bar/td_notice_bar.dart b/tdesign-component/lib/src/components/notice_bar/td_notice_bar.dart index ba7d030c1..591caa303 100644 --- a/tdesign-component/lib/src/components/notice_bar/td_notice_bar.dart +++ b/tdesign-component/lib/src/components/notice_bar/td_notice_bar.dart @@ -23,6 +23,7 @@ class TDNoticeBar extends StatefulWidget { this.prefixIcon, this.suffixIcon, this.onTap, + this.height = 22, }); /// 文本内容 @@ -61,6 +62,9 @@ class TDNoticeBar extends StatefulWidget { /// 点击事件 final ValueChanged? onTap; + /// 文字高度 (当使用prefixIcon或suffixIcon时,icon大小值等于该属性) + final double height; + @override State createState() => _TDNoticeBarState(); } @@ -158,7 +162,7 @@ class _TDNoticeBarState extends State { var step = 0; var offset = 0.0; _timer = Timer.periodic(Duration(milliseconds: widget.interval!), (timer) { - var time = (22 / widget.speed! * 1000).round(); + var time = (widget.height / widget.speed! * 1000).round(); if (step >= widget.context.length) { step = 0; offset = 0; @@ -166,7 +170,7 @@ class _TDNoticeBarState extends State { } step++; // 固定滚动行高(22) - offset += 22; + offset += widget.height; _scrollController!.animateTo(offset, duration: Duration(milliseconds: time), curve: Curves.linear); }); @@ -196,7 +200,7 @@ class _TDNoticeBarState extends State { _left = Icon( widget.prefixIcon, color: _style!.leftIconColor, - size: 22, + size: widget.height, ); } if (widget.left != null) { @@ -210,7 +214,7 @@ class _TDNoticeBarState extends State { _right = Icon( widget.suffixIcon, color: _style!.rightIconColor, - size: 22, + size: widget.height, ); } if (widget.right != null) { @@ -245,20 +249,30 @@ class _TDNoticeBarState extends State { if (widget.context is String) { valid = true; textWidget = SizedBox( - height: 22, + height: widget.height, child: Align( alignment: Alignment.centerLeft, - child: TDText(widget.context, style: _style?.getTextStyle, maxLines: 1), + child: TDText( + widget.context, + style: _style?.getTextStyle, + maxLines: 1, + forceVerticalCenter: true, + ), ), ); } if (widget.context is List) { valid = true; textWidget = SizedBox( - height: 22, + height: widget.height, child: Align( alignment: Alignment.centerLeft, - child: TDText(widget.context[0], style: _style?.getTextStyle, maxLines: 1), + child: TDText( + widget.context[0], + style: _style?.getTextStyle, + maxLines: 1, + forceVerticalCenter: true, + ), ), ); } @@ -279,7 +293,7 @@ class _TDNoticeBarState extends State { children: [ SizedBox( key: _key, - height: 22, + height: widget.height, child: textWidget, ), SizedBox(width: _getEmptyWidth()), @@ -287,7 +301,7 @@ class _TDNoticeBarState extends State { width: _getEmptyWidth() > _getContextWidth() ? _getEmptyWidth() : _getContextWidth(), - height: 22, + height: widget.height, child: textWidget, ) ], @@ -297,7 +311,7 @@ class _TDNoticeBarState extends State { case Axis.vertical: var contexts = widget.context as List; child = SizedBox( - height: 22, + height: widget.height, child: SingleChildScrollView( controller: _scrollController, scrollDirection: Axis.vertical, @@ -308,7 +322,7 @@ class _TDNoticeBarState extends State { children: [ for (int i = 0; i < contexts.length; i++) SizedBox( - height: 22, + height: widget.height, child: Align( alignment: Alignment.centerLeft, child: TDText( @@ -321,7 +335,7 @@ class _TDNoticeBarState extends State { ), SizedBox( key: _key, - height: 22, + height: widget.height, child: Align( alignment: Alignment.centerLeft, child: TDText( @@ -359,6 +373,7 @@ class _TDNoticeBarState extends State { ), child: Row( crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, children: [ Visibility( visible: _left != null,