Unverified Commit 595df47f authored by Madhur Maurya's avatar Madhur Maurya Committed by GitHub

Tab bar improvements (#63683)

* indicatorPadding now does not get ignored

* Removing unnecessary comments

* Throw FlutterError on indicatorPadding

* Tests for indicatorPadding

* Migrate test to NNBD

* Tests Renamed
parent 6cec03c7
...@@ -321,6 +321,7 @@ class _IndicatorPainter extends CustomPainter { ...@@ -321,6 +321,7 @@ class _IndicatorPainter extends CustomPainter {
required this.indicatorSize, required this.indicatorSize,
required this.tabKeys, required this.tabKeys,
required _IndicatorPainter? old, required _IndicatorPainter? old,
required this.indicatorPadding,
}) : assert(controller != null), }) : assert(controller != null),
assert(indicator != null), assert(indicator != null),
super(repaint: controller.animation) { super(repaint: controller.animation) {
...@@ -331,6 +332,7 @@ class _IndicatorPainter extends CustomPainter { ...@@ -331,6 +332,7 @@ class _IndicatorPainter extends CustomPainter {
final TabController controller; final TabController controller;
final Decoration indicator; final Decoration indicator;
final TabBarIndicatorSize? indicatorSize; final TabBarIndicatorSize? indicatorSize;
final EdgeInsetsGeometry indicatorPadding;
final List<GlobalKey> tabKeys; final List<GlobalKey> tabKeys;
// _currentTabOffsets and _currentTextDirection are set each time TabBar // _currentTabOffsets and _currentTextDirection are set each time TabBar
...@@ -392,7 +394,16 @@ class _IndicatorPainter extends CustomPainter { ...@@ -392,7 +394,16 @@ class _IndicatorPainter extends CustomPainter {
tabRight -= delta; tabRight -= delta;
} }
return Rect.fromLTWH(tabLeft, 0.0, tabRight - tabLeft, tabBarSize.height); final EdgeInsets insets = indicatorPadding.resolve(_currentTextDirection);
final Rect rect = Rect.fromLTWH(tabLeft, 0.0, tabRight - tabLeft, tabBarSize.height);
if (!(rect.size >= insets.collapsedSize)) {
throw FlutterError(
'indicatorPadding insets should be less than Tab Size\n'
'Rect Size : ${rect.size}, Insets: ${insets.toString()}'
);
}
return insets.deflateRect(rect);
} }
@override @override
...@@ -658,26 +669,22 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -658,26 +669,22 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
/// this property is ignored. /// this property is ignored.
final double indicatorWeight; final double indicatorWeight;
/// The horizontal padding for the line that appears below the selected tab.
/// Padding for indicator.
/// This property will now no longer be ignored even if indicator is declared
/// or provided by [TabBarTheme]
/// ///
/// For [isScrollable] tab bars, specifying [kTabLabelPadding] will align /// For [isScrollable] tab bars, specifying [kTabLabelPadding] will align
/// the indicator with the tab's text for [Tab] widgets and all but the /// the indicator with the tab's text for [Tab] widgets and all but the
/// shortest [Tab.text] values. /// shortest [Tab.text] values.
/// ///
/// The [EdgeInsets.top] and [EdgeInsets.bottom] values of the
/// [indicatorPadding] are ignored.
///
/// The default value of [indicatorPadding] is [EdgeInsets.zero]. /// The default value of [indicatorPadding] is [EdgeInsets.zero].
///
/// If [indicator] is specified or provided from [TabBarTheme],
/// this property is ignored.
final EdgeInsetsGeometry indicatorPadding; final EdgeInsetsGeometry indicatorPadding;
/// Defines the appearance of the selected tab indicator. /// Defines the appearance of the selected tab indicator.
/// ///
/// If [indicator] is specified or provided from [TabBarTheme], /// If [indicator] is specified or provided from [TabBarTheme],
/// the [indicatorColor], [indicatorWeight], and [indicatorPadding] /// the [indicatorColor], and [indicatorWeight] properties are ignored.
/// properties are ignored.
/// ///
/// The default, underline-style, selected tab indicator can be defined with /// The default, underline-style, selected tab indicator can be defined with
/// [UnderlineTabIndicator]. /// [UnderlineTabIndicator].
...@@ -857,7 +864,6 @@ class _TabBarState extends State<TabBar> { ...@@ -857,7 +864,6 @@ class _TabBarState extends State<TabBar> {
color = Colors.white; color = Colors.white;
return UnderlineTabIndicator( return UnderlineTabIndicator(
insets: widget.indicatorPadding,
borderSide: BorderSide( borderSide: BorderSide(
width: widget.indicatorWeight, width: widget.indicatorWeight,
color: color, color: color,
...@@ -905,6 +911,7 @@ class _TabBarState extends State<TabBar> { ...@@ -905,6 +911,7 @@ class _TabBarState extends State<TabBar> {
controller: _controller!, controller: _controller!,
indicator: _indicator, indicator: _indicator,
indicatorSize: widget.indicatorSize ?? TabBarTheme.of(context).indicatorSize, indicatorSize: widget.indicatorSize ?? TabBarTheme.of(context).indicatorSize,
indicatorPadding: widget.indicatorPadding,
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