Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labelStyle、unselectedLabelStyle支持自定义Lable的文字大小 #453

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions tdesign-component/lib/src/components/tabs/td_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ class TDTab extends Tab {
this.outlineType = TDTabOutlineType.filled,
this.enable = true,
this.iconMargin = const EdgeInsets.only(bottom: 4.0, right: 4.0)})
: super(
key: key,
text: text,
child: child,
icon: icon,
height: height,
iconMargin: iconMargin);
: super(key: key, text: text, child: child, icon: icon, height: height, iconMargin: iconMargin);

final double _kTabHeight = 48.0;
final double _kTextAndIconTabHeight = 72.0;
Expand All @@ -83,7 +77,7 @@ class TDTab extends Tab {
Widget label;
if (icon == null) {
calculatedHeight = _kTabHeight;
label = _buildLabelText();
label = _buildLabelText(context);
} else if (text == null && child == null) {
calculatedHeight = _kTabHeight;
label = icon!;
Expand All @@ -98,7 +92,7 @@ class TDTab extends Tab {
width: iconMargin.horizontal,
height: iconMargin.vertical,
),
_buildLabelText(),
_buildLabelText(context),
],
);
}
Expand All @@ -121,9 +115,7 @@ class TDTab extends Tab {
ignoring: !enable,
child: Container(
alignment: Alignment.center,
margin: isCapsuleOutlineType
? const EdgeInsets.symmetric(horizontal: 16)
: null,
margin: isCapsuleOutlineType ? const EdgeInsets.symmetric(horizontal: 16) : null,
height: height ?? calculatedHeight,
child: Center(
widthFactor: 1.0,
Expand All @@ -133,17 +125,26 @@ class TDTab extends Tab {
);
}

Widget _buildLabelText() {
return child ??
Text(
text!,
softWrap: false,
overflow: TextOverflow.fade,
style: TextStyle(fontSize: _getFontSize()),
);
Widget _buildLabelText(BuildContext context) {
if (child != null) {
return DefaultTextStyle(
child: child!,
style: DefaultTextStyle.of(context).style.copyWith(fontSize: TDTheme.of(context).fontBodySmall?.size ?? 14),
);
}
return Text(
text!,
softWrap: false,
overflow: TextOverflow.fade,
style: TextStyle(fontSize: _getFontSize(context)),
);
}

double _getFontSize() {
double _getFontSize(BuildContext context) {
final defaultTextStyle = DefaultTextStyle.of(context);
if (defaultTextStyle.style.fontSize != null) {
return defaultTextStyle.style.fontSize!;
}
if (size == TDTabSize.large) {
return 16.0;
} else {
Expand Down
4 changes: 2 additions & 2 deletions tdesign-component/lib/src/components/tabs/td_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ class _TDTabBarState extends State<TDTabBar> {
TextStyle _getUnSelectLabelStyle(BuildContext context) {
return TextStyle(
fontWeight: FontWeight.w400,
fontSize: TDTheme.of(context).fontBodySmall?.size ?? 14,
// fontSize: TDTheme.of(context).fontBodySmall?.size ?? 14,
color: TDTheme.of(context).fontGyColor2);
}

TextStyle _getLabelStyle(BuildContext context) {
return TextStyle(
fontWeight: FontWeight.w600,
fontSize: TDTheme.of(context).fontBodySmall?.size ?? 14,
// fontSize: TDTheme.of(context).fontBodySmall?.size ?? 14,
color: TDTheme.of(context).fontGyColor2);
}

Expand Down
Loading