Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9adbc51

Browse files
authored
Deprecate ThemeData.indicatorColor in favor of TabBarThemeData.indicatorColor (#160024)
Related to [☂️ Material Theme System Updates](#91772) ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent b4a81cb commit 9adbc51

File tree

7 files changed

+152
-58
lines changed

7 files changed

+152
-58
lines changed

packages/flutter/lib/fix_data/fix_material/fix_theme_data.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,68 @@
2626
# * WidgetState: fix_widget_state.yaml
2727
version: 1
2828
transforms:
29+
# Changes made in https://github.com/flutter/flutter/pull/160024
30+
- title: "Migrate 'ThemeData.indicatorColor' to 'TabBarThemeData.indicatorColor'"
31+
date: 2025-01-03
32+
element:
33+
uris: [ 'material.dart' ]
34+
method: 'copyWith'
35+
inClass: 'ThemeData'
36+
oneOf:
37+
- if: "indicatorColor != '' && tabBarTheme != ''"
38+
changes:
39+
- kind: 'removeParameter'
40+
name: 'indicatorColor'
41+
- if: "indicatorColor != '' && tabBarTheme == ''"
42+
changes:
43+
- kind: 'removeParameter'
44+
name: 'indicatorColor'
45+
- kind: 'addParameter'
46+
index: 136
47+
name: 'tabBarTheme'
48+
style: optional_named
49+
argumentValue:
50+
expression: 'TabBarThemeData(indicatorColor: {% indicatorColor %})'
51+
requiredIf: "indicatorColor != ''"
52+
variables:
53+
indicatorColor:
54+
kind: 'fragment'
55+
value: 'arguments[indicatorColor]'
56+
tabBarTheme:
57+
kind: 'fragment'
58+
value: 'arguments[tabBarTheme]'
59+
60+
# Changes made in https://github.com/flutter/flutter/pull/160024
61+
- title: "Migrate 'ThemeData.indicatorColor' to 'TabBarThemeData.indicatorColor'"
62+
date: 2025-01-03
63+
element:
64+
uris: [ 'material.dart' ]
65+
constructor: ''
66+
inClass: 'ThemeData'
67+
oneOf:
68+
- if: "indicatorColor != '' && tabBarTheme != ''"
69+
changes:
70+
- kind: 'removeParameter'
71+
name: 'indicatorColor'
72+
- if: "indicatorColor != '' && tabBarTheme == ''"
73+
changes:
74+
- kind: 'removeParameter'
75+
name: 'indicatorColor'
76+
- kind: 'addParameter'
77+
index: 136
78+
name: 'tabBarTheme'
79+
style: optional_named
80+
argumentValue:
81+
expression: 'TabBarThemeData(indicatorColor: {% indicatorColor %})'
82+
requiredIf: "indicatorColor != ''"
83+
variables:
84+
indicatorColor:
85+
kind: 'fragment'
86+
value: 'arguments[indicatorColor]'
87+
tabBarTheme:
88+
kind: 'fragment'
89+
value: 'arguments[tabBarTheme]'
90+
2991
# Changes made in https://github.com/flutter/flutter/pull/155072
3092
- title: "Migrate 'ThemeData.dialogBackgroundColor' to 'DialogThemeData.backgroundColor'"
3193
date: 2024-09-12

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,14 +2565,16 @@ class _TabPageSelectorState extends State<TabPageSelector> {
25652565

25662566
// Hand coded defaults based on Material Design 2.
25672567
class _TabsDefaultsM2 extends TabBarThemeData {
2568-
const _TabsDefaultsM2(this.context, this.isScrollable)
2569-
: super(indicatorSize: TabBarIndicatorSize.tab);
2568+
_TabsDefaultsM2(this.context, this.isScrollable) : super(indicatorSize: TabBarIndicatorSize.tab);
25702569

25712570
final BuildContext context;
2571+
late final ColorScheme _colors = Theme.of(context).colorScheme;
2572+
late final bool isDark = Theme.of(context).brightness == Brightness.dark;
2573+
late final Color primaryColor = isDark ? Colors.grey[900]! : Colors.blue;
25722574
final bool isScrollable;
25732575

25742576
@override
2575-
Color? get indicatorColor => Theme.of(context).indicatorColor;
2577+
Color? get indicatorColor => _colors.secondary == primaryColor ? Colors.white : _colors.secondary;
25762578

25772579
@override
25782580
Color? get labelColor => Theme.of(context).primaryTextTheme.bodyLarge!.color!;

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

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ class ThemeData with Diagnosticable {
286286
Color? highlightColor,
287287
Color? hintColor,
288288
Color? hoverColor,
289-
Color? indicatorColor,
290289
Color? primaryColor,
291290
Color? primaryColorDark,
292291
Color? primaryColorLight,
@@ -365,6 +364,11 @@ class ThemeData with Diagnosticable {
365364
'This feature was deprecated after v3.27.0-0.1.pre.',
366365
)
367366
Color? dialogBackgroundColor,
367+
@Deprecated(
368+
'Use TabBarThemeData.indicatorColor instead. '
369+
'This feature was deprecated after v3.28.0-1.0.pre.',
370+
)
371+
Color? indicatorColor,
368372
}) {
369373
// GENERAL CONFIGURATION
370374
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
@@ -459,7 +463,6 @@ class ThemeData with Diagnosticable {
459463
unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
460464
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
461465
secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!;
462-
indicatorColor ??= colorScheme.secondary == primaryColor ? Colors.white : colorScheme.secondary;
463466
hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6);
464467
// The default [buttonTheme] is here because it doesn't use the defaults for
465468
// [disabledColor], [highlightColor], and [splashColor].
@@ -580,6 +583,7 @@ class ThemeData with Diagnosticable {
580583
// DEPRECATED (newest deprecations at the bottom)
581584
buttonBarTheme ??= const ButtonBarThemeData();
582585
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
586+
indicatorColor ??= colorScheme.secondary == primaryColor ? Colors.white : colorScheme.secondary;
583587
return ThemeData.raw(
584588
// For the sanity of the reader, make sure these properties are in the same
585589
// order in every place that they are separated by section comments (e.g.
@@ -609,7 +613,6 @@ class ThemeData with Diagnosticable {
609613
highlightColor: highlightColor,
610614
hintColor: hintColor,
611615
hoverColor: hoverColor,
612-
indicatorColor: indicatorColor,
613616
primaryColor: primaryColor,
614617
primaryColorDark: primaryColorDark,
615618
primaryColorLight: primaryColorLight,
@@ -673,6 +676,7 @@ class ThemeData with Diagnosticable {
673676
// DEPRECATED (newest deprecations at the bottom)
674677
buttonBarTheme: buttonBarTheme,
675678
dialogBackgroundColor: dialogBackgroundColor,
679+
indicatorColor: indicatorColor,
676680
);
677681
}
678682

@@ -715,7 +719,6 @@ class ThemeData with Diagnosticable {
715719
required this.highlightColor,
716720
required this.hintColor,
717721
required this.hoverColor,
718-
required this.indicatorColor,
719722
required this.primaryColor,
720723
required this.primaryColorDark,
721724
required this.primaryColorLight,
@@ -787,6 +790,11 @@ class ThemeData with Diagnosticable {
787790
'This feature was deprecated after v3.27.0-0.1.pre.',
788791
)
789792
required this.dialogBackgroundColor,
793+
@Deprecated(
794+
'Use TabBarThemeData.indicatorColor instead. '
795+
'This feature was deprecated after v3.28.0-1.0.pre.',
796+
)
797+
required this.indicatorColor,
790798
}) : // DEPRECATED (newest deprecations at the bottom)
791799
// should not be `required`, use getter pattern to avoid breakages.
792800
_buttonBarTheme = buttonBarTheme,
@@ -1204,9 +1212,6 @@ class ThemeData with Diagnosticable {
12041212
/// component.
12051213
final Color hoverColor;
12061214

1207-
/// The color of the selected tab indicator in a tab bar.
1208-
final Color indicatorColor;
1209-
12101215
/// The background color for major parts of the app (toolbars, tab bars, etc)
12111216
///
12121217
/// The theme's [colorScheme] property contains [ColorScheme.primary], as
@@ -1451,6 +1456,13 @@ class ThemeData with Diagnosticable {
14511456
)
14521457
final Color dialogBackgroundColor;
14531458

1459+
/// The color of the selected tab indicator in a tab bar.
1460+
@Deprecated(
1461+
'Use TabBarThemeData.indicatorColor instead. '
1462+
'This feature was deprecated after v3.28.0-1.0.pre.',
1463+
)
1464+
final Color indicatorColor;
1465+
14541466
/// Creates a copy of this theme but with the given fields replaced with the new values.
14551467
///
14561468
/// The [brightness] value is applied to the [colorScheme].
@@ -1486,7 +1498,6 @@ class ThemeData with Diagnosticable {
14861498
Color? highlightColor,
14871499
Color? hintColor,
14881500
Color? hoverColor,
1489-
Color? indicatorColor,
14901501
Color? primaryColor,
14911502
Color? primaryColorDark,
14921503
Color? primaryColorLight,
@@ -1568,6 +1579,11 @@ class ThemeData with Diagnosticable {
15681579
'This feature was deprecated after v3.27.0-0.1.pre.',
15691580
)
15701581
Color? dialogBackgroundColor,
1582+
@Deprecated(
1583+
'Use TabBarThemeData.indicatorColor instead. '
1584+
'This feature was deprecated after v3.28.0-1.0.pre.',
1585+
)
1586+
Color? indicatorColor,
15711587
}) {
15721588
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
15731589

@@ -1628,7 +1644,6 @@ class ThemeData with Diagnosticable {
16281644
highlightColor: highlightColor ?? this.highlightColor,
16291645
hintColor: hintColor ?? this.hintColor,
16301646
hoverColor: hoverColor ?? this.hoverColor,
1631-
indicatorColor: indicatorColor ?? this.indicatorColor,
16321647
primaryColor: primaryColor ?? this.primaryColor,
16331648
primaryColorDark: primaryColorDark ?? this.primaryColorDark,
16341649
primaryColorLight: primaryColorLight ?? this.primaryColorLight,
@@ -1692,6 +1707,7 @@ class ThemeData with Diagnosticable {
16921707
// DEPRECATED (newest deprecations at the bottom)
16931708
buttonBarTheme: buttonBarTheme ?? _buttonBarTheme,
16941709
dialogBackgroundColor: dialogBackgroundColor ?? this.dialogBackgroundColor,
1710+
indicatorColor: indicatorColor ?? this.indicatorColor,
16951711
);
16961712
}
16971713

@@ -1835,7 +1851,6 @@ class ThemeData with Diagnosticable {
18351851
highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t)!,
18361852
hintColor: Color.lerp(a.hintColor, b.hintColor, t)!,
18371853
hoverColor: Color.lerp(a.hoverColor, b.hoverColor, t)!,
1838-
indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t)!,
18391854
primaryColor: Color.lerp(a.primaryColor, b.primaryColor, t)!,
18401855
primaryColorDark: Color.lerp(a.primaryColorDark, b.primaryColorDark, t)!,
18411856
primaryColorLight: Color.lerp(a.primaryColorLight, b.primaryColorLight, t)!,
@@ -1921,6 +1936,7 @@ class ThemeData with Diagnosticable {
19211936
// DEPRECATED (newest deprecations at the bottom)
19221937
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t),
19231938
dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t)!,
1939+
indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t)!,
19241940
);
19251941
}
19261942

@@ -1957,7 +1973,6 @@ class ThemeData with Diagnosticable {
19571973
other.highlightColor == highlightColor &&
19581974
other.hintColor == hintColor &&
19591975
other.hoverColor == hoverColor &&
1960-
other.indicatorColor == indicatorColor &&
19611976
other.primaryColor == primaryColor &&
19621977
other.primaryColorDark == primaryColorDark &&
19631978
other.primaryColorLight == primaryColorLight &&
@@ -2020,7 +2035,8 @@ class ThemeData with Diagnosticable {
20202035
other.tooltipTheme == tooltipTheme &&
20212036
// DEPRECATED (newest deprecations at the bottom)
20222037
other.buttonBarTheme == buttonBarTheme &&
2023-
other.dialogBackgroundColor == dialogBackgroundColor;
2038+
other.dialogBackgroundColor == dialogBackgroundColor &&
2039+
other.indicatorColor == indicatorColor;
20242040
}
20252041

20262042
@override
@@ -2056,7 +2072,6 @@ class ThemeData with Diagnosticable {
20562072
highlightColor,
20572073
hintColor,
20582074
hoverColor,
2059-
indicatorColor,
20602075
primaryColor,
20612076
primaryColorDark,
20622077
primaryColorLight,
@@ -2120,6 +2135,7 @@ class ThemeData with Diagnosticable {
21202135
// DEPRECATED (newest deprecations at the bottom)
21212136
buttonBarTheme,
21222137
dialogBackgroundColor,
2138+
indicatorColor,
21232139
];
21242140
return Object.hashAll(values);
21252141
}
@@ -2299,14 +2315,6 @@ class ThemeData with Diagnosticable {
22992315
level: DiagnosticLevel.debug,
23002316
),
23012317
);
2302-
properties.add(
2303-
ColorProperty(
2304-
'indicatorColor',
2305-
indicatorColor,
2306-
defaultValue: defaultData.indicatorColor,
2307-
level: DiagnosticLevel.debug,
2308-
),
2309-
);
23102318
properties.add(
23112319
ColorProperty(
23122320
'primaryColorDark',
@@ -2761,6 +2769,14 @@ class ThemeData with Diagnosticable {
27612769
level: DiagnosticLevel.debug,
27622770
),
27632771
);
2772+
properties.add(
2773+
ColorProperty(
2774+
'indicatorColor',
2775+
indicatorColor,
2776+
defaultValue: defaultData.indicatorColor,
2777+
level: DiagnosticLevel.debug,
2778+
),
2779+
);
27642780
}
27652781
}
27662782

packages/flutter/test/material/tab_bar_theme_test.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,13 +1473,11 @@ void main() {
14731473
final TabController controller = TabController(vsync: const TestVSync(), length: tabs.length);
14741474
addTearDown(controller.dispose);
14751475

1476-
const Color themeIndicatorColor = Color(0xffff0000);
14771476
const Color tabBarThemeIndicatorColor = Color(0xffffff00);
14781477

1479-
Widget buildTabBar({Color? themeIndicatorColor, Color? tabBarThemeIndicatorColor}) {
1478+
Widget buildTabBar({Color? tabBarThemeIndicatorColor}) {
14801479
return MaterialApp(
14811480
theme: ThemeData(
1482-
indicatorColor: themeIndicatorColor,
14831481
tabBarTheme: TabBarThemeData(indicatorColor: tabBarThemeIndicatorColor),
14841482
useMaterial3: false,
14851483
),
@@ -1492,15 +1490,9 @@ void main() {
14921490
);
14931491
}
14941492

1495-
await tester.pumpWidget(buildTabBar(themeIndicatorColor: themeIndicatorColor));
1496-
1497-
RenderBox tabBarBox = tester.firstRenderObject<RenderBox>(find.byType(TabBar));
1498-
expect(tabBarBox, paints..line(color: themeIndicatorColor));
1499-
15001493
await tester.pumpWidget(buildTabBar(tabBarThemeIndicatorColor: tabBarThemeIndicatorColor));
1501-
await tester.pumpAndSettle();
15021494

1503-
tabBarBox = tester.firstRenderObject<RenderBox>(find.byType(TabBar));
1495+
final RenderBox tabBarBox = tester.firstRenderObject<RenderBox>(find.byType(TabBar));
15041496
expect(tabBarBox, paints..line(color: tabBarThemeIndicatorColor));
15051497
});
15061498

0 commit comments

Comments
 (0)