From 87f1487e56a072676c1601b263697b9b1ad82099 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 25 Feb 2017 23:39:22 -0800 Subject: [PATCH] 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. --- packages/flutter/lib/src/material/tabs.dart | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 594065eb08..653261d036 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -109,9 +109,13 @@ class _TabStyle extends AnimatedWidget { this.selected, this.labelColor, this.unselectedLabelColor, + this.labelStyle, + this.unselectedLabelStyle, @required this.child, }) : super(key: key, animation: animation); + final TextStyle labelStyle; + final TextStyle unselectedLabelStyle; final bool selected; final Color labelColor; final Color unselectedLabelColor; @@ -120,7 +124,11 @@ class _TabStyle extends AnimatedWidget { @override Widget build(BuildContext 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 unselectedColor = unselectedLabelColor ?? selectedColor.withAlpha(0xB2); // 70% alpha final Color color = selected @@ -340,7 +348,9 @@ class TabBar extends StatefulWidget implements AppBarBottomWidget { this.isScrollable: false, this.indicatorColor, this.labelColor, + this.labelStyle, this.unselectedLabelColor, + this.unselectedLabelStyle, }) : super(key: key) { assert(tabs != null && tabs.length > 1); assert(isScrollable != null); @@ -381,6 +391,20 @@ class TabBar extends StatefulWidget implements AppBarBottomWidget { /// [labelColor] rendered at 70% opacity. 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 double get bottomHeight { for (Widget widget in tabs) { @@ -542,6 +566,8 @@ class _TabBarState extends State { selected: true, labelColor: config.labelColor, unselectedLabelColor: config.unselectedLabelColor, + labelStyle: config.labelStyle, + unselectedLabelStyle: config.unselectedLabelStyle, child: wrappedTabs[_currentIndex], ); wrappedTabs[previousIndex] = new _TabStyle( @@ -549,6 +575,8 @@ class _TabBarState extends State { selected: false, labelColor: config.labelColor, unselectedLabelColor: config.unselectedLabelColor, + labelStyle: config.labelStyle, + unselectedLabelStyle: config.unselectedLabelStyle, child: wrappedTabs[previousIndex], ); } else { @@ -557,6 +585,8 @@ class _TabBarState extends State { selected: true, labelColor: config.labelColor, unselectedLabelColor: config.unselectedLabelColor, + labelStyle: config.labelStyle, + unselectedLabelStyle: config.unselectedLabelStyle, child: wrappedTabs[_currentIndex], ); } @@ -583,6 +613,8 @@ class _TabBarState extends State { selected: false, labelColor: config.labelColor, unselectedLabelColor: config.unselectedLabelColor, + labelStyle: config.labelStyle, + unselectedLabelStyle: config.unselectedLabelStyle, child: new _TabLabelBar( onPerformLayout: _saveTabOffsets, children: wrappedTabs,