From db105353cf066ab0868cc0b8723f3c20d0e0813d Mon Sep 17 00:00:00 2001 From: ccXxx1aoBai <1426169428@qq.com> Date: Thu, 18 Jul 2024 16:47:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=A0=B7=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/lib/page/td_notice_bar_page.dart | 7 +- .../components/notice_bar/td_notice_bar.dart | 69 ++++++++++++------- .../notice_bar/td_notice_bar_style.dart | 7 +- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/tdesign-component/example/lib/page/td_notice_bar_page.dart b/tdesign-component/example/lib/page/td_notice_bar_page.dart index 0693ead0e..770f9301a 100644 --- a/tdesign-component/example/lib/page/td_notice_bar_page.dart +++ b/tdesign-component/example/lib/page/td_notice_bar_page.dart @@ -103,6 +103,9 @@ Widget _entranceNoticeBar1(BuildContext context) { text: '文字按钮', type: TDButtonType.text, theme: TDButtonTheme.primary, + size: TDButtonSize.extraSmall, + height: 22, + padding: EdgeInsets.symmetric(vertical: 0, horizontal: 0), ), ); } @@ -241,7 +244,9 @@ Widget _leftNoticeBar(BuildContext context) { text: '文本', type: TDButtonType.text, theme: TDButtonTheme.primary, - size: TDButtonSize.small, + size: TDButtonSize.extraSmall, + height: 22, + padding: EdgeInsets.symmetric(vertical: 0, horizontal: 0), ), ); } 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 71ef65f03..ba7d030c1 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 @@ -155,19 +155,18 @@ class _TDNoticeBarState extends State { } void _step() { - var textHeight = _getFontSize().height; var step = 0; var offset = 0.0; - _timer = - Timer.periodic(Duration(milliseconds: widget.interval!), (timer) { - var time = (textHeight / widget.speed! * 1000).round(); + _timer = Timer.periodic(Duration(milliseconds: widget.interval!), (timer) { + var time = (22 / widget.speed! * 1000).round(); if (step >= widget.context.length) { step = 0; offset = 0; _scrollController!.jumpTo(0); } step++; - offset += textHeight; + // 固定滚动行高(22) + offset += 22; _scrollController!.animateTo(offset, duration: Duration(milliseconds: time), curve: Curves.linear); }); @@ -197,7 +196,7 @@ class _TDNoticeBarState extends State { _left = Icon( widget.prefixIcon, color: _style!.leftIconColor, - size: 24, + size: 22, ); } if (widget.left != null) { @@ -211,7 +210,7 @@ class _TDNoticeBarState extends State { _right = Icon( widget.suffixIcon, color: _style!.rightIconColor, - size: 24, + size: 22, ); } if (widget.right != null) { @@ -245,11 +244,23 @@ class _TDNoticeBarState extends State { Widget? textWidget; if (widget.context is String) { valid = true; - textWidget = TDText(widget.context, style: _style?.getTextStyle); + textWidget = SizedBox( + height: 22, + child: Align( + alignment: Alignment.centerLeft, + child: TDText(widget.context, style: _style?.getTextStyle, maxLines: 1), + ), + ); } if (widget.context is List) { valid = true; - textWidget = TDText(widget.context[0], style: _style?.getTextStyle); + textWidget = SizedBox( + height: 22, + child: Align( + alignment: Alignment.centerLeft, + child: TDText(widget.context[0], style: _style?.getTextStyle, maxLines: 1), + ), + ); } if (!valid) { throw Exception('context must be String or List'); @@ -268,7 +279,7 @@ class _TDNoticeBarState extends State { children: [ SizedBox( key: _key, - height: _getFontSize().height, + height: 22, child: textWidget, ), SizedBox(width: _getEmptyWidth()), @@ -276,7 +287,7 @@ class _TDNoticeBarState extends State { width: _getEmptyWidth() > _getContextWidth() ? _getEmptyWidth() : _getContextWidth(), - height: _getFontSize().height, + height: 22, child: textWidget, ) ], @@ -286,7 +297,7 @@ class _TDNoticeBarState extends State { case Axis.vertical: var contexts = widget.context as List; child = SizedBox( - height: _getFontSize().height, + height: 22, child: SingleChildScrollView( controller: _scrollController, scrollDirection: Axis.vertical, @@ -297,22 +308,30 @@ class _TDNoticeBarState extends State { children: [ for (int i = 0; i < contexts.length; i++) SizedBox( - child: TDText( - contexts[i], - style: _style!.getTextStyle, - maxLines: 1, - overflow: TextOverflow.ellipsis, + height: 22, + child: Align( + alignment: Alignment.centerLeft, + child: TDText( + contexts[i], + style: _style!.getTextStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), ), ), SizedBox( key: _key, - child: TDText( - contexts[0], - style: _style?.getTextStyle, - maxLines: 1, - overflow: TextOverflow.ellipsis, + height: 22, + child: Align( + alignment: Alignment.centerLeft, + child: TDText( + contexts[0], + style: _style?.getTextStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), ), - ) + ), ]), ), ); @@ -362,9 +381,7 @@ class _TDNoticeBarState extends State { visible: _right != null, child: GestureDetector( onTap: () => _onTap('suffix-icon'), - child: Container( - child: _right, - ), + child: _right, ), ), ], diff --git a/tdesign-component/lib/src/components/notice_bar/td_notice_bar_style.dart b/tdesign-component/lib/src/components/notice_bar/td_notice_bar_style.dart index 12a32dbf5..b08c4e184 100644 --- a/tdesign-component/lib/src/components/notice_bar/td_notice_bar_style.dart +++ b/tdesign-component/lib/src/components/notice_bar/td_notice_bar_style.dart @@ -68,7 +68,12 @@ class TDNoticeBarStyle { TextStyle get getTextStyle => textStyle ?? TextStyle( - color: TDTheme.of(context).fontGyColor1, fontSize: 16, height: 1); + color: TDTheme.of(context).fontGyColor1, + fontSize: 14, + height: 1, + fontWeight: FontWeight.normal, + fontStyle: FontStyle.normal, + ); /// 根据主题生成样式 TDNoticeBarStyle.generateTheme(BuildContext context,