Skip to content

Commit

Permalink
组件样式修改
Browse files Browse the repository at this point in the history
  • Loading branch information
ccXxx1aoBai committed Jul 18, 2024
1 parent 05ee575 commit db10535
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
7 changes: 6 additions & 1 deletion tdesign-component/example/lib/page/td_notice_bar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
);
}
Expand Down Expand Up @@ -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),
),
);
}
Expand Down
69 changes: 43 additions & 26 deletions tdesign-component/lib/src/components/notice_bar/td_notice_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,18 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
}

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);
});
Expand Down Expand Up @@ -197,7 +196,7 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
_left = Icon(
widget.prefixIcon,
color: _style!.leftIconColor,
size: 24,
size: 22,
);
}
if (widget.left != null) {
Expand All @@ -211,7 +210,7 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
_right = Icon(
widget.suffixIcon,
color: _style!.rightIconColor,
size: 24,
size: 22,
);
}
if (widget.right != null) {
Expand Down Expand Up @@ -245,11 +244,23 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
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<String>) {
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<String>');
Expand All @@ -268,15 +279,15 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
children: [
SizedBox(
key: _key,
height: _getFontSize().height,
height: 22,
child: textWidget,
),
SizedBox(width: _getEmptyWidth()),
SizedBox(
width: _getEmptyWidth() > _getContextWidth()
? _getEmptyWidth()
: _getContextWidth(),
height: _getFontSize().height,
height: 22,
child: textWidget,
)
],
Expand All @@ -286,7 +297,7 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
case Axis.vertical:
var contexts = widget.context as List<String>;
child = SizedBox(
height: _getFontSize().height,
height: 22,
child: SingleChildScrollView(
controller: _scrollController,
scrollDirection: Axis.vertical,
Expand All @@ -297,22 +308,30 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
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,
),
),
)
),
]),
),
);
Expand Down Expand Up @@ -362,9 +381,7 @@ class _TDNoticeBarState extends State<TDNoticeBar> {
visible: _right != null,
child: GestureDetector(
onTap: () => _onTap('suffix-icon'),
child: Container(
child: _right,
),
child: _right,
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit db10535

Please sign in to comment.