[Material] Create TabBarTheme.of constructor (#23702)
* Create TabBarTheme of(...) constructor * First round comments * fix imports
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'tabs.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
/// Defines a theme for [TabBar] widgets.
|
||||
///
|
||||
@@ -13,9 +15,8 @@ import 'tabs.dart';
|
||||
/// the [TabBar.indicator].
|
||||
///
|
||||
/// Descendant widgets obtain the current theme's [TabBarTheme] object using
|
||||
/// `Theme.of(context).tabBarTheme`.
|
||||
/// [ThemeData.tabBarTheme] can be customized by copying it (using
|
||||
/// [TabBarTheme.copyWith]).
|
||||
/// `TabBarTheme.of(context)`. Instances of [TabBarTheme] can be customized with
|
||||
/// [TabBarTheme.copyWith].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
@@ -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.
|
||||
///
|
||||
/// The arguments must not be null.
|
||||
|
||||
@@ -150,7 +150,7 @@ class _TabStyle extends AnimatedWidget {
|
||||
@override
|
||||
Widget build(BuildContext 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 defaultUnselectedStyle = unselectedLabelStyle ?? labelStyle ?? themeData.primaryTextTheme.body2;
|
||||
@@ -513,7 +513,7 @@ class _TabBarScrollController extends ScrollController {
|
||||
///
|
||||
/// 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:
|
||||
///
|
||||
@@ -698,11 +698,11 @@ class _TabBarState extends State<TabBar> {
|
||||
Decoration get _indicator {
|
||||
if (widget.indicator != null)
|
||||
return widget.indicator;
|
||||
final ThemeData themeData = Theme.of(context);
|
||||
if (themeData.tabBarTheme.indicator != null)
|
||||
return themeData.tabBarTheme.indicator;
|
||||
final TabBarTheme tabBarTheme = TabBarTheme.of(context);
|
||||
if (tabBarTheme.indicator != null)
|
||||
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
|
||||
// primaryColor. However, it's possible that the tab bar is on a
|
||||
// Material that isn't the primaryColor. In that case, if the indicator
|
||||
@@ -755,7 +755,7 @@ class _TabBarState extends State<TabBar> {
|
||||
_indicatorPainter = _controller == null ? null : _IndicatorPainter(
|
||||
controller: _controller,
|
||||
indicator: _indicator,
|
||||
indicatorSize: widget.indicatorSize ?? Theme.of(context).tabBarTheme.indicatorSize,
|
||||
indicatorSize: widget.indicatorSize ?? TabBarTheme.of(context).indicatorSize,
|
||||
tabKeys: _tabKeys,
|
||||
old: _indicatorPainter,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user