Commit 87f1487e authored by Luke's avatar Luke Committed by Adam Barth

Adds un/selected text styles to the TabBar widget (#8417)

* Adds un/selected text styles to the TabBar widget

* Adding documentation on fallback values. Modified fallback on unselectedLabelStyle.
parent 6b97757b
...@@ -109,9 +109,13 @@ class _TabStyle extends AnimatedWidget { ...@@ -109,9 +109,13 @@ class _TabStyle extends AnimatedWidget {
this.selected, this.selected,
this.labelColor, this.labelColor,
this.unselectedLabelColor, this.unselectedLabelColor,
this.labelStyle,
this.unselectedLabelStyle,
@required this.child, @required this.child,
}) : super(key: key, animation: animation); }) : super(key: key, animation: animation);
final TextStyle labelStyle;
final TextStyle unselectedLabelStyle;
final bool selected; final bool selected;
final Color labelColor; final Color labelColor;
final Color unselectedLabelColor; final Color unselectedLabelColor;
...@@ -120,7 +124,11 @@ class _TabStyle extends AnimatedWidget { ...@@ -120,7 +124,11 @@ class _TabStyle extends AnimatedWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context); final ThemeData themeData = Theme.of(context);
final TextStyle textStyle = themeData.primaryTextTheme.body2; final TextStyle defaultStyle = labelStyle ?? themeData.primaryTextTheme.body2;
final TextStyle defaultUnselectedStyle = unselectedLabelStyle ?? labelStyle ?? themeData.primaryTextTheme.body2;
final TextStyle textStyle = selected
? defaultStyle
: defaultUnselectedStyle;
final Color selectedColor = labelColor ?? themeData.primaryTextTheme.body2.color; final Color selectedColor = labelColor ?? themeData.primaryTextTheme.body2.color;
final Color unselectedColor = unselectedLabelColor ?? selectedColor.withAlpha(0xB2); // 70% alpha final Color unselectedColor = unselectedLabelColor ?? selectedColor.withAlpha(0xB2); // 70% alpha
final Color color = selected final Color color = selected
...@@ -340,7 +348,9 @@ class TabBar extends StatefulWidget implements AppBarBottomWidget { ...@@ -340,7 +348,9 @@ class TabBar extends StatefulWidget implements AppBarBottomWidget {
this.isScrollable: false, this.isScrollable: false,
this.indicatorColor, this.indicatorColor,
this.labelColor, this.labelColor,
this.labelStyle,
this.unselectedLabelColor, this.unselectedLabelColor,
this.unselectedLabelStyle,
}) : super(key: key) { }) : super(key: key) {
assert(tabs != null && tabs.length > 1); assert(tabs != null && tabs.length > 1);
assert(isScrollable != null); assert(isScrollable != null);
...@@ -381,6 +391,20 @@ class TabBar extends StatefulWidget implements AppBarBottomWidget { ...@@ -381,6 +391,20 @@ class TabBar extends StatefulWidget implements AppBarBottomWidget {
/// [labelColor] rendered at 70% opacity. /// [labelColor] rendered at 70% opacity.
final Color unselectedLabelColor; final Color unselectedLabelColor;
/// The text style of the selected tab labels. If [unselectedLabelStyle] is
/// null then this text style will be used for both selected and unselected
/// label styles.
///
/// If this property is null then the text style of the theme's body2
/// definition is used.
final TextStyle labelStyle;
/// The text style of the unselected tab labels
///
/// If this property is null then the [labelStyle] value is used. If [labelStyle]
/// is null then the text style of the theme's body2 definition is used.
final TextStyle unselectedLabelStyle;
@override @override
double get bottomHeight { double get bottomHeight {
for (Widget widget in tabs) { for (Widget widget in tabs) {
...@@ -542,6 +566,8 @@ class _TabBarState extends State<TabBar> { ...@@ -542,6 +566,8 @@ class _TabBarState extends State<TabBar> {
selected: true, selected: true,
labelColor: config.labelColor, labelColor: config.labelColor,
unselectedLabelColor: config.unselectedLabelColor, unselectedLabelColor: config.unselectedLabelColor,
labelStyle: config.labelStyle,
unselectedLabelStyle: config.unselectedLabelStyle,
child: wrappedTabs[_currentIndex], child: wrappedTabs[_currentIndex],
); );
wrappedTabs[previousIndex] = new _TabStyle( wrappedTabs[previousIndex] = new _TabStyle(
...@@ -549,6 +575,8 @@ class _TabBarState extends State<TabBar> { ...@@ -549,6 +575,8 @@ class _TabBarState extends State<TabBar> {
selected: false, selected: false,
labelColor: config.labelColor, labelColor: config.labelColor,
unselectedLabelColor: config.unselectedLabelColor, unselectedLabelColor: config.unselectedLabelColor,
labelStyle: config.labelStyle,
unselectedLabelStyle: config.unselectedLabelStyle,
child: wrappedTabs[previousIndex], child: wrappedTabs[previousIndex],
); );
} else { } else {
...@@ -557,6 +585,8 @@ class _TabBarState extends State<TabBar> { ...@@ -557,6 +585,8 @@ class _TabBarState extends State<TabBar> {
selected: true, selected: true,
labelColor: config.labelColor, labelColor: config.labelColor,
unselectedLabelColor: config.unselectedLabelColor, unselectedLabelColor: config.unselectedLabelColor,
labelStyle: config.labelStyle,
unselectedLabelStyle: config.unselectedLabelStyle,
child: wrappedTabs[_currentIndex], child: wrappedTabs[_currentIndex],
); );
} }
...@@ -583,6 +613,8 @@ class _TabBarState extends State<TabBar> { ...@@ -583,6 +613,8 @@ class _TabBarState extends State<TabBar> {
selected: false, selected: false,
labelColor: config.labelColor, labelColor: config.labelColor,
unselectedLabelColor: config.unselectedLabelColor, unselectedLabelColor: config.unselectedLabelColor,
labelStyle: config.labelStyle,
unselectedLabelStyle: config.unselectedLabelStyle,
child: new _TabLabelBar( child: new _TabLabelBar(
onPerformLayout: _saveTabOffsets, onPerformLayout: _saveTabOffsets,
children: wrappedTabs, children: wrappedTabs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment