Unverified Commit b8c3e0db authored by MH Johnson's avatar MH Johnson Committed by GitHub

[Material] Create TabBarTheme.of constructor (#23702)

* Create TabBarTheme of(...) constructor

* First round comments

* fix imports
parent f9c6f305
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'tabs.dart'; import 'tabs.dart';
import 'theme.dart';
/// Defines a theme for [TabBar] widgets. /// Defines a theme for [TabBar] widgets.
/// ///
...@@ -13,9 +15,8 @@ import 'tabs.dart'; ...@@ -13,9 +15,8 @@ import 'tabs.dart';
/// the [TabBar.indicator]. /// the [TabBar.indicator].
/// ///
/// Descendant widgets obtain the current theme's [TabBarTheme] object using /// Descendant widgets obtain the current theme's [TabBarTheme] object using
/// `Theme.of(context).tabBarTheme`. /// `TabBarTheme.of(context)`. Instances of [TabBarTheme] can be customized with
/// [ThemeData.tabBarTheme] can be customized by copying it (using /// [TabBarTheme.copyWith].
/// [TabBarTheme.copyWith]).
/// ///
/// See also: /// See also:
/// ///
...@@ -59,6 +60,11 @@ class TabBarTheme extends Diagnosticable { ...@@ -59,6 +60,11 @@ class TabBarTheme extends Diagnosticable {
); );
} }
/// The data from the closest [TabBarTheme] instance given the build context.
static TabBarTheme of(BuildContext context) {
return Theme.of(context).tabBarTheme;
}
/// Linearly interpolate between two tab bar themes. /// Linearly interpolate between two tab bar themes.
/// ///
/// The arguments must not be null. /// The arguments must not be null.
......
...@@ -150,7 +150,7 @@ class _TabStyle extends AnimatedWidget { ...@@ -150,7 +150,7 @@ 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 TabBarTheme tabBarTheme = themeData.tabBarTheme; final TabBarTheme tabBarTheme = TabBarTheme.of(context);
final TextStyle defaultStyle = labelStyle ?? themeData.primaryTextTheme.body2; final TextStyle defaultStyle = labelStyle ?? themeData.primaryTextTheme.body2;
final TextStyle defaultUnselectedStyle = unselectedLabelStyle ?? labelStyle ?? themeData.primaryTextTheme.body2; final TextStyle defaultUnselectedStyle = unselectedLabelStyle ?? labelStyle ?? themeData.primaryTextTheme.body2;
...@@ -513,7 +513,7 @@ class _TabBarScrollController extends ScrollController { ...@@ -513,7 +513,7 @@ class _TabBarScrollController extends ScrollController {
/// ///
/// Requires one of its ancestors to be a [Material] widget. /// Requires one of its ancestors to be a [Material] widget.
/// ///
/// Uses values from [ThemeData.tabBarTheme] if it is set in the current context. /// Uses values from [TabBarTheme] if it is set in the current context.
/// ///
/// See also: /// See also:
/// ///
...@@ -698,11 +698,11 @@ class _TabBarState extends State<TabBar> { ...@@ -698,11 +698,11 @@ class _TabBarState extends State<TabBar> {
Decoration get _indicator { Decoration get _indicator {
if (widget.indicator != null) if (widget.indicator != null)
return widget.indicator; return widget.indicator;
final ThemeData themeData = Theme.of(context); final TabBarTheme tabBarTheme = TabBarTheme.of(context);
if (themeData.tabBarTheme.indicator != null) if (tabBarTheme.indicator != null)
return themeData.tabBarTheme.indicator; return tabBarTheme.indicator;
Color color = widget.indicatorColor ?? themeData.indicatorColor; Color color = widget.indicatorColor ?? Theme.of(context).indicatorColor;
// ThemeData tries to avoid this by having indicatorColor avoid being the // ThemeData tries to avoid this by having indicatorColor avoid being the
// primaryColor. However, it's possible that the tab bar is on a // primaryColor. However, it's possible that the tab bar is on a
// Material that isn't the primaryColor. In that case, if the indicator // Material that isn't the primaryColor. In that case, if the indicator
...@@ -755,7 +755,7 @@ class _TabBarState extends State<TabBar> { ...@@ -755,7 +755,7 @@ class _TabBarState extends State<TabBar> {
_indicatorPainter = _controller == null ? null : _IndicatorPainter( _indicatorPainter = _controller == null ? null : _IndicatorPainter(
controller: _controller, controller: _controller,
indicator: _indicator, indicator: _indicator,
indicatorSize: widget.indicatorSize ?? Theme.of(context).tabBarTheme.indicatorSize, indicatorSize: widget.indicatorSize ?? TabBarTheme.of(context).indicatorSize,
tabKeys: _tabKeys, tabKeys: _tabKeys,
old: _indicatorPainter, old: _indicatorPainter,
); );
......
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