Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b2672fe

Browse files
authored
Revert "Add Material 3 support for TabBar (#116110)" (#116273)
This reverts commit 900b395.
1 parent 02de129 commit b2672fe

File tree

7 files changed

+64
-523
lines changed

7 files changed

+64
-523
lines changed

dev/tools/gen_defaults/bin/gen_defaults.dart

-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import 'package:gen_defaults/segmented_button_template.dart';
4646
import 'package:gen_defaults/slider_template.dart';
4747
import 'package:gen_defaults/surface_tint.dart';
4848
import 'package:gen_defaults/switch_template.dart';
49-
import 'package:gen_defaults/tabs_template.dart';
5049
import 'package:gen_defaults/text_field_template.dart';
5150
import 'package:gen_defaults/typography_template.dart';
5251

@@ -166,6 +165,5 @@ Future<void> main(List<String> args) async {
166165
SurfaceTintTemplate('SurfaceTint', '$materialLib/elevation_overlay.dart', tokens).updateFile();
167166
SwitchTemplate('Switch', '$materialLib/switch.dart', tokens).updateFile();
168167
TextFieldTemplate('TextField', '$materialLib/text_field.dart', tokens).updateFile();
169-
TabsTemplate('Tabs', '$materialLib/tabs.dart', tokens).updateFile();
170168
TypographyTemplate('Typography', '$materialLib/typography.dart', tokens).updateFile();
171169
}

dev/tools/gen_defaults/lib/tabs_template.dart

-73
This file was deleted.

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

+37-19
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class TabBarTheme with Diagnosticable {
2929
/// Creates a tab bar theme that can be used with [ThemeData.tabBarTheme].
3030
const TabBarTheme({
3131
this.indicator,
32-
this.indicatorColor,
3332
this.indicatorSize,
34-
this.dividerColor,
3533
this.labelColor,
3634
this.labelPadding,
3735
this.labelStyle,
@@ -45,15 +43,9 @@ class TabBarTheme with Diagnosticable {
4543
/// Overrides the default value for [TabBar.indicator].
4644
final Decoration? indicator;
4745

48-
/// Overrides the default value for [TabBar.indicatorColor].
49-
final Color? indicatorColor;
50-
5146
/// Overrides the default value for [TabBar.indicatorSize].
5247
final TabBarIndicatorSize? indicatorSize;
5348

54-
/// Overrides the default value for [TabBar.dividerColor].
55-
final Color? dividerColor;
56-
5749
/// Overrides the default value for [TabBar.labelColor].
5850
final Color? labelColor;
5951

@@ -88,9 +80,7 @@ class TabBarTheme with Diagnosticable {
8880
/// new values.
8981
TabBarTheme copyWith({
9082
Decoration? indicator,
91-
Color? indicatorColor,
9283
TabBarIndicatorSize? indicatorSize,
93-
Color? dividerColor,
9484
Color? labelColor,
9585
EdgeInsetsGeometry? labelPadding,
9686
TextStyle? labelStyle,
@@ -102,9 +92,7 @@ class TabBarTheme with Diagnosticable {
10292
}) {
10393
return TabBarTheme(
10494
indicator: indicator ?? this.indicator,
105-
indicatorColor: indicatorColor ?? this.indicatorColor,
10695
indicatorSize: indicatorSize ?? this.indicatorSize,
107-
dividerColor: dividerColor ?? this.dividerColor,
10896
labelColor: labelColor ?? this.labelColor,
10997
labelPadding: labelPadding ?? this.labelPadding,
11098
labelStyle: labelStyle ?? this.labelStyle,
@@ -132,15 +120,13 @@ class TabBarTheme with Diagnosticable {
132120
assert(t != null);
133121
return TabBarTheme(
134122
indicator: Decoration.lerp(a.indicator, b.indicator, t),
135-
indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t),
136123
indicatorSize: t < 0.5 ? a.indicatorSize : b.indicatorSize,
137-
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t),
138124
labelColor: Color.lerp(a.labelColor, b.labelColor, t),
139125
labelPadding: EdgeInsetsGeometry.lerp(a.labelPadding, b.labelPadding, t),
140126
labelStyle: TextStyle.lerp(a.labelStyle, b.labelStyle, t),
141127
unselectedLabelColor: Color.lerp(a.unselectedLabelColor, b.unselectedLabelColor, t),
142128
unselectedLabelStyle: TextStyle.lerp(a.unselectedLabelStyle, b.unselectedLabelStyle, t),
143-
overlayColor: MaterialStateProperty.lerp<Color?>(a.overlayColor, b.overlayColor, t, Color.lerp),
129+
overlayColor: _LerpColors(a.overlayColor, b.overlayColor, t),
144130
splashFactory: t < 0.5 ? a.splashFactory : b.splashFactory,
145131
mouseCursor: t < 0.5 ? a.mouseCursor : b.mouseCursor,
146132
);
@@ -149,9 +135,7 @@ class TabBarTheme with Diagnosticable {
149135
@override
150136
int get hashCode => Object.hash(
151137
indicator,
152-
indicatorColor,
153138
indicatorSize,
154-
dividerColor,
155139
labelColor,
156140
labelPadding,
157141
labelStyle,
@@ -172,9 +156,7 @@ class TabBarTheme with Diagnosticable {
172156
}
173157
return other is TabBarTheme
174158
&& other.indicator == indicator
175-
&& other.indicatorColor == indicatorColor
176159
&& other.indicatorSize == indicatorSize
177-
&& other.dividerColor == dividerColor
178160
&& other.labelColor == labelColor
179161
&& other.labelPadding == labelPadding
180162
&& other.labelStyle == labelStyle
@@ -185,3 +167,39 @@ class TabBarTheme with Diagnosticable {
185167
&& other.mouseCursor == mouseCursor;
186168
}
187169
}
170+
171+
172+
@immutable
173+
class _LerpColors implements MaterialStateProperty<Color?> {
174+
const _LerpColors(this.a, this.b, this.t);
175+
176+
final MaterialStateProperty<Color?>? a;
177+
final MaterialStateProperty<Color?>? b;
178+
final double t;
179+
180+
@override
181+
Color? resolve(Set<MaterialState> states) {
182+
final Color? resolvedA = a?.resolve(states);
183+
final Color? resolvedB = b?.resolve(states);
184+
return Color.lerp(resolvedA, resolvedB, t);
185+
}
186+
187+
@override
188+
int get hashCode {
189+
return Object.hash(a, b, t);
190+
}
191+
192+
@override
193+
bool operator ==(Object other) {
194+
if (identical(this, other)) {
195+
return true;
196+
}
197+
if (other.runtimeType != runtimeType) {
198+
return false;
199+
}
200+
return other is _LerpColors
201+
&& other.a == a
202+
&& other.b == b
203+
&& other.t == t;
204+
}
205+
}

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

+5-38
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,11 @@ class UnderlineTabIndicator extends Decoration {
2020
///
2121
/// The [borderSide] and [insets] arguments must not be null.
2222
const UnderlineTabIndicator({
23-
this.borderRadius,
2423
this.borderSide = const BorderSide(width: 2.0, color: Colors.white),
2524
this.insets = EdgeInsets.zero,
2625
}) : assert(borderSide != null),
2726
assert(insets != null);
2827

29-
/// The radius of the indicator's corners.
30-
///
31-
/// If this value is non-null, rounded rectangular tab indicator is
32-
/// drawn, otherwise rectangular tab indictor is drawn.
33-
final BorderRadius? borderRadius;
34-
3528
/// The color and weight of the horizontal line drawn below the selected tab.
3629
final BorderSide borderSide;
3730

@@ -67,7 +60,7 @@ class UnderlineTabIndicator extends Decoration {
6760

6861
@override
6962
BoxPainter createBoxPainter([ VoidCallback? onChanged ]) {
70-
return _UnderlinePainter(this, borderRadius, onChanged);
63+
return _UnderlinePainter(this, onChanged);
7164
}
7265

7366
Rect _indicatorRectFor(Rect rect, TextDirection textDirection) {
@@ -84,50 +77,24 @@ class UnderlineTabIndicator extends Decoration {
8477

8578
@override
8679
Path getClipPath(Rect rect, TextDirection textDirection) {
87-
if (borderRadius != null) {
88-
return Path()..addRRect(
89-
borderRadius!.toRRect(_indicatorRectFor(rect, textDirection))
90-
);
91-
}
9280
return Path()..addRect(_indicatorRectFor(rect, textDirection));
9381
}
9482
}
9583

9684
class _UnderlinePainter extends BoxPainter {
97-
_UnderlinePainter(
98-
this.decoration,
99-
this.borderRadius,
100-
super.onChanged,
101-
)
85+
_UnderlinePainter(this.decoration, super.onChanged)
10286
: assert(decoration != null);
10387

10488
final UnderlineTabIndicator decoration;
105-
final BorderRadius? borderRadius;
10689

10790
@override
10891
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
10992
assert(configuration != null);
11093
assert(configuration.size != null);
11194
final Rect rect = offset & configuration.size!;
11295
final TextDirection textDirection = configuration.textDirection!;
113-
final Paint paint;
114-
if (borderRadius != null) {
115-
paint = Paint()..color = decoration.borderSide.color;
116-
final Rect indicator = decoration._indicatorRectFor(rect, textDirection)
117-
.inflate(decoration.borderSide.width / 4.0);
118-
final RRect rrect = RRect.fromRectAndCorners(
119-
indicator,
120-
topLeft: borderRadius!.topLeft,
121-
topRight: borderRadius!.topRight,
122-
bottomRight: borderRadius!.bottomRight,
123-
bottomLeft: borderRadius!.bottomLeft,
124-
);
125-
canvas.drawRRect(rrect, paint);
126-
} else {
127-
paint = decoration.borderSide.toPaint()..strokeCap = StrokeCap.square;
128-
final Rect indicator = decoration._indicatorRectFor(rect, textDirection)
129-
.deflate(decoration.borderSide.width / 2.0);
130-
canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint);
131-
}
96+
final Rect indicator = decoration._indicatorRectFor(rect, textDirection).deflate(decoration.borderSide.width / 2.0);
97+
final Paint paint = decoration.borderSide.toPaint()..strokeCap = StrokeCap.square;
98+
canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint);
13299
}
133100
}

0 commit comments

Comments
 (0)