Skip to content

Commit 087377e

Browse files
authored
Revert "Fix Material 3 Scrollable TabBar" (#129383)
Reverts flutter/flutter#125974
1 parent 7e2f3fa commit 087377e

File tree

6 files changed

+43
-624
lines changed

6 files changed

+43
-624
lines changed

dev/tools/gen_defaults/generated/used_tokens.csv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ md.comp.primary-navigation-tab.active.hover.state-layer.opacity,
529529
md.comp.primary-navigation-tab.active.pressed.state-layer.color,
530530
md.comp.primary-navigation-tab.active.pressed.state-layer.opacity,
531531
md.comp.primary-navigation-tab.divider.color,
532-
md.comp.primary-navigation-tab.divider.height,
533532
md.comp.primary-navigation-tab.inactive.focus.state-layer.color,
534533
md.comp.primary-navigation-tab.inactive.focus.state-layer.opacity,
535534
md.comp.primary-navigation-tab.inactive.hover.state-layer.color,
@@ -589,7 +588,6 @@ md.comp.search-view.header.supporting-text.color,
589588
md.comp.search-view.header.supporting-text.text-style,
590589
md.comp.secondary-navigation-tab.active.label-text.color,
591590
md.comp.secondary-navigation-tab.divider.color,
592-
md.comp.secondary-navigation-tab.divider.height,
593591
md.comp.secondary-navigation-tab.focus.state-layer.color,
594592
md.comp.secondary-navigation-tab.focus.state-layer.opacity,
595593
md.comp.secondary-navigation-tab.hover.state-layer.color,

dev/tools/gen_defaults/lib/tabs_template.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class _${blockName}PrimaryDefaultsM3 extends TabBarTheme {
2424
@override
2525
Color? get dividerColor => ${componentColor("md.comp.primary-navigation-tab.divider")};
2626
27-
@override
28-
double? get dividerHeight => ${getToken('md.comp.primary-navigation-tab.divider.height')};
29-
3027
@override
3128
Color? get indicatorColor => ${componentColor("md.comp.primary-navigation-tab.active-indicator")};
3229
@@ -74,7 +71,7 @@ class _${blockName}PrimaryDefaultsM3 extends TabBarTheme {
7471
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
7572
7673
@override
77-
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
74+
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.start : TabAlignment.fill;
7875
7976
static double indicatorWeight = ${getToken('md.comp.primary-navigation-tab.active-indicator.height')};
8077
}
@@ -91,9 +88,6 @@ class _${blockName}SecondaryDefaultsM3 extends TabBarTheme {
9188
@override
9289
Color? get dividerColor => ${componentColor("md.comp.secondary-navigation-tab.divider")};
9390
94-
@override
95-
double? get dividerHeight => ${getToken('md.comp.secondary-navigation-tab.divider.height')};
96-
9791
@override
9892
Color? get indicatorColor => ${componentColor("md.comp.primary-navigation-tab.active-indicator")};
9993
@@ -141,7 +135,7 @@ class _${blockName}SecondaryDefaultsM3 extends TabBarTheme {
141135
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
142136
143137
@override
144-
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
138+
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.start : TabAlignment.fill;
145139
}
146140
''';
147141

packages/flutter/lib/src/material/tab_bar_theme.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class TabBarTheme with Diagnosticable {
3232
this.indicatorColor,
3333
this.indicatorSize,
3434
this.dividerColor,
35-
this.dividerHeight,
3635
this.labelColor,
3736
this.labelPadding,
3837
this.labelStyle,
@@ -56,9 +55,6 @@ class TabBarTheme with Diagnosticable {
5655
/// Overrides the default value for [TabBar.dividerColor].
5756
final Color? dividerColor;
5857

59-
/// Overrides the default value for [TabBar.dividerHeight].
60-
final double? dividerHeight;
61-
6258
/// Overrides the default value for [TabBar.labelColor].
6359
///
6460
/// If [labelColor] is a [MaterialStateColor], then the effective color will
@@ -105,7 +101,6 @@ class TabBarTheme with Diagnosticable {
105101
Color? indicatorColor,
106102
TabBarIndicatorSize? indicatorSize,
107103
Color? dividerColor,
108-
double? dividerHeight,
109104
Color? labelColor,
110105
EdgeInsetsGeometry? labelPadding,
111106
TextStyle? labelStyle,
@@ -121,7 +116,6 @@ class TabBarTheme with Diagnosticable {
121116
indicatorColor: indicatorColor ?? this.indicatorColor,
122117
indicatorSize: indicatorSize ?? this.indicatorSize,
123118
dividerColor: dividerColor ?? this.dividerColor,
124-
dividerHeight: dividerHeight ?? this.dividerHeight,
125119
labelColor: labelColor ?? this.labelColor,
126120
labelPadding: labelPadding ?? this.labelPadding,
127121
labelStyle: labelStyle ?? this.labelStyle,
@@ -153,7 +147,6 @@ class TabBarTheme with Diagnosticable {
153147
indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t),
154148
indicatorSize: t < 0.5 ? a.indicatorSize : b.indicatorSize,
155149
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t),
156-
dividerHeight: t < 0.5 ? a.dividerHeight : b.dividerHeight,
157150
labelColor: Color.lerp(a.labelColor, b.labelColor, t),
158151
labelPadding: EdgeInsetsGeometry.lerp(a.labelPadding, b.labelPadding, t),
159152
labelStyle: TextStyle.lerp(a.labelStyle, b.labelStyle, t),
@@ -172,7 +165,6 @@ class TabBarTheme with Diagnosticable {
172165
indicatorColor,
173166
indicatorSize,
174167
dividerColor,
175-
dividerHeight,
176168
labelColor,
177169
labelPadding,
178170
labelStyle,
@@ -197,7 +189,6 @@ class TabBarTheme with Diagnosticable {
197189
&& other.indicatorColor == indicatorColor
198190
&& other.indicatorSize == indicatorSize
199191
&& other.dividerColor == dividerColor
200-
&& other.dividerHeight == dividerHeight
201192
&& other.labelColor == labelColor
202193
&& other.labelPadding == labelPadding
203194
&& other.labelStyle == labelStyle

packages/flutter/lib/src/material/tabs.dart

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,6 @@ class _IndicatorPainter extends CustomPainter {
397397
required this.indicatorPadding,
398398
required this.labelPaddings,
399399
this.dividerColor,
400-
this.dividerHeight,
401-
required this.width,
402400
}) : super(repaint: controller.animation) {
403401
if (old != null) {
404402
saveTabOffsets(old._currentTabOffsets, old._currentTextDirection);
@@ -410,10 +408,8 @@ class _IndicatorPainter extends CustomPainter {
410408
final TabBarIndicatorSize? indicatorSize;
411409
final EdgeInsetsGeometry indicatorPadding;
412410
final List<GlobalKey> tabKeys;
413-
final List<EdgeInsetsGeometry> labelPaddings;
414411
final Color? dividerColor;
415-
final double? dividerHeight;
416-
final double width;
412+
final List<EdgeInsetsGeometry> labelPaddings;
417413

418414
// _currentTabOffsets and _currentTextDirection are set each time TabBar
419415
// layout is completed. These values can be null when TabBar contains no
@@ -506,10 +502,8 @@ class _IndicatorPainter extends CustomPainter {
506502
textDirection: _currentTextDirection,
507503
);
508504
if (dividerColor != null) {
509-
final Paint dividerPaint = Paint()..color = dividerColor!..strokeWidth = dividerHeight!;
510-
final Offset dividerP1 = Offset(-width, size.height - (dividerPaint.strokeWidth / 2));
511-
final Offset dividerP2 = Offset(width, size.height - (dividerPaint.strokeWidth / 2));
512-
canvas.drawLine(dividerP1, dividerP2, dividerPaint);
505+
final Paint dividerPaint = Paint()..color = dividerColor!..strokeWidth = 1;
506+
canvas.drawLine(Offset(0, size.height), Offset(size.width, size.height), dividerPaint);
513507
}
514508
_painter!.paint(canvas, _currentRect!.topLeft, configuration);
515509
}
@@ -724,7 +718,6 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
724718
this.indicator,
725719
this.indicatorSize,
726720
this.dividerColor,
727-
this.dividerHeight,
728721
this.labelColor,
729722
this.labelStyle,
730723
this.labelPadding,
@@ -775,7 +768,6 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
775768
this.indicator,
776769
this.indicatorSize,
777770
this.dividerColor,
778-
this.dividerHeight,
779771
this.labelColor,
780772
this.labelStyle,
781773
this.labelPadding,
@@ -903,13 +895,6 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
903895
/// [ColorScheme.surfaceVariant] will be used, otherwise divider will not be drawn.
904896
final Color? dividerColor;
905897

906-
/// The height of the divider.
907-
///
908-
/// If null and [ThemeData.useMaterial3] is true, [TabBarTheme.dividerHeight] is used.
909-
/// If that is also null and [ThemeData.useMaterial3] is true, 1.0 will be used.
910-
/// Otherwise divider will not be drawn.
911-
final double? dividerHeight;
912-
913898
/// The color of selected tab labels.
914899
///
915900
/// If null, then [TabBarTheme.labelColor] is used. If that is also null and
@@ -1169,8 +1154,8 @@ class _TabBarState extends State<TabBar> {
11691154
TabBarTheme get _defaults {
11701155
if (Theme.of(context).useMaterial3) {
11711156
return widget._isPrimary
1172-
? _TabsPrimaryDefaultsM3(context, widget.isScrollable)
1173-
: _TabsSecondaryDefaultsM3(context, widget.isScrollable);
1157+
? _TabsPrimaryDefaultsM3(context, widget.isScrollable)
1158+
: _TabsSecondaryDefaultsM3(context, widget.isScrollable);
11741159
} else {
11751160
return _TabsDefaultsM2(context, widget.isScrollable);
11761161
}
@@ -1284,10 +1269,8 @@ class _TabBarState extends State<TabBar> {
12841269
indicatorPadding: widget.indicatorPadding,
12851270
tabKeys: _tabKeys,
12861271
old: _indicatorPainter,
1287-
labelPaddings: _labelPaddings,
12881272
dividerColor: theme.useMaterial3 ? widget.dividerColor ?? tabBarTheme.dividerColor ?? _defaults.dividerColor : null,
1289-
dividerHeight: theme.useMaterial3 ? widget.dividerHeight ?? tabBarTheme.dividerHeight ?? _defaults.dividerHeight : null,
1290-
width: MediaQuery.sizeOf(context).width,
1273+
labelPaddings: _labelPaddings,
12911274
);
12921275
}
12931276

@@ -1492,7 +1475,6 @@ class _TabBarState extends State<TabBar> {
14921475
Widget build(BuildContext context) {
14931476
assert(debugCheckHasMaterialLocalizations(context));
14941477
assert(_debugScheduleCheckHasValidTabsCount());
1495-
final ThemeData theme = Theme.of(context);
14961478
final TabBarTheme tabBarTheme = TabBarTheme.of(context);
14971479
final TabAlignment effectiveTabAlignment = widget.tabAlignment ?? tabBarTheme.tabAlignment ?? _defaults.tabAlignment!;
14981480
assert(_debugTabAlignmentIsValid(effectiveTabAlignment));
@@ -1645,17 +1627,6 @@ class _TabBarState extends State<TabBar> {
16451627
child: tabBar,
16461628
),
16471629
);
1648-
if (theme.useMaterial3) {
1649-
final AlignmentGeometry effectiveAlignment = switch (effectiveTabAlignment) {
1650-
TabAlignment.center => Alignment.center,
1651-
TabAlignment.start || TabAlignment.startOffset || TabAlignment.fill => AlignmentDirectional.centerStart,
1652-
};
1653-
tabBar = Align(
1654-
heightFactor: 1.0,
1655-
alignment: effectiveAlignment,
1656-
child: tabBar,
1657-
);
1658-
}
16591630
} else if (widget.padding != null) {
16601631
tabBar = Padding(
16611632
padding: widget.padding!,
@@ -2206,9 +2177,6 @@ class _TabsPrimaryDefaultsM3 extends TabBarTheme {
22062177
@override
22072178
Color? get dividerColor => _colors.surfaceVariant;
22082179

2209-
@override
2210-
double? get dividerHeight => 1.0;
2211-
22122180
@override
22132181
Color? get indicatorColor => _colors.primary;
22142182

@@ -2256,7 +2224,7 @@ class _TabsPrimaryDefaultsM3 extends TabBarTheme {
22562224
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
22572225

22582226
@override
2259-
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
2227+
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.start : TabAlignment.fill;
22602228

22612229
static double indicatorWeight = 3.0;
22622230
}
@@ -2273,9 +2241,6 @@ class _TabsSecondaryDefaultsM3 extends TabBarTheme {
22732241
@override
22742242
Color? get dividerColor => _colors.surfaceVariant;
22752243

2276-
@override
2277-
double? get dividerHeight => 1.0;
2278-
22792244
@override
22802245
Color? get indicatorColor => _colors.primary;
22812246

@@ -2323,7 +2288,7 @@ class _TabsSecondaryDefaultsM3 extends TabBarTheme {
23232288
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
23242289

23252290
@override
2326-
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
2291+
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.start : TabAlignment.fill;
23272292
}
23282293

23292294
// END GENERATED TOKEN PROPERTIES - Tabs

0 commit comments

Comments
 (0)