Skip to content

Commit f99f472

Browse files
authored
Remove the deprecated accentColor from ThemeData (#120932)
Co-authored-by: Qun Cheng <[email protected]>
1 parent 6104505 commit f99f472

File tree

3 files changed

+4
-68
lines changed

3 files changed

+4
-68
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum ButtonTextTheme {
2323
/// Button text is black or white depending on [ThemeData.brightness].
2424
normal,
2525

26-
/// Button text is [ThemeData.accentColor].
26+
/// Button text is [ColorScheme.secondary].
2727
accent,
2828

2929
/// Button text is based on [ThemeData.primaryColor].

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

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,6 @@ class ThemeData with Diagnosticable {
381381
ToggleButtonsThemeData? toggleButtonsTheme,
382382
TooltipThemeData? tooltipTheme,
383383
// DEPRECATED (newest deprecations at the bottom)
384-
@Deprecated(
385-
'Use colorScheme.secondary instead. '
386-
'For more information, consult the migration guide at '
387-
'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
388-
'This feature was deprecated after v2.3.0-0.1.pre.',
389-
)
390-
Color? accentColor,
391384
@Deprecated(
392385
'This "fix" is now enabled by default. '
393386
'This feature was deprecated after v2.5.0-1.0.pre.',
@@ -478,7 +471,6 @@ class ThemeData with Diagnosticable {
478471
primaryColor ??= primarySurfaceColor;
479472
primaryColorBrightness = ThemeData.estimateBrightnessForColor(primarySurfaceColor);
480473
canvasColor ??= colorScheme.background;
481-
accentColor ??= colorScheme.secondary;
482474
scaffoldBackgroundColor ??= colorScheme.background;
483475
bottomAppBarColor ??= colorScheme.surface;
484476
cardColor ??= colorScheme.surface;
@@ -496,8 +488,7 @@ class ThemeData with Diagnosticable {
496488
primaryColorLight ??= isDark ? Colors.grey[500]! : primarySwatch[100]!;
497489
primaryColorDark ??= isDark ? Colors.black : primarySwatch[700]!;
498490
final bool primaryIsDark = estimatedPrimaryColorBrightness == Brightness.dark;
499-
toggleableActiveColor ??= isDark ? Colors.tealAccent[200]! : (accentColor ?? primarySwatch[600]!);
500-
accentColor ??= isDark ? Colors.tealAccent[200]! : primarySwatch[500]!;
491+
toggleableActiveColor ??= isDark ? Colors.tealAccent[200]! : (colorScheme?.secondary ?? primarySwatch[600]!);
501492
focusColor ??= isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.12);
502493
hoverColor ??= isDark ? Colors.white.withOpacity(0.04) : Colors.black.withOpacity(0.04);
503494
shadowColor ??= Colors.black;
@@ -510,7 +501,7 @@ class ThemeData with Diagnosticable {
510501
colorScheme ??= ColorScheme.fromSwatch(
511502
primarySwatch: primarySwatch,
512503
primaryColorDark: primaryColorDark,
513-
accentColor: accentColor,
504+
accentColor: isDark ? Colors.tealAccent[200]! : primarySwatch[500]!,
514505
cardColor: cardColor,
515506
backgroundColor: isDark ? Colors.grey[700]! : primarySwatch[200]!,
516507
errorColor: Colors.red[700],
@@ -521,7 +512,7 @@ class ThemeData with Diagnosticable {
521512
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
522513
secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!;
523514
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
524-
indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor;
515+
indicatorColor ??= colorScheme.secondary == primaryColor ? Colors.white : colorScheme.secondary;
525516
hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6);
526517
// The default [buttonTheme] is here because it doesn't use the defaults for
527518
// [disabledColor], [highlightColor], and [splashColor].
@@ -702,7 +693,6 @@ class ThemeData with Diagnosticable {
702693
toggleButtonsTheme: toggleButtonsTheme,
703694
tooltipTheme: tooltipTheme,
704695
// DEPRECATED (newest deprecations at the bottom)
705-
accentColor: accentColor,
706696
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
707697
primaryColorBrightness: primaryColorBrightness,
708698
androidOverscrollIndicator: androidOverscrollIndicator,
@@ -813,13 +803,6 @@ class ThemeData with Diagnosticable {
813803
required this.toggleButtonsTheme,
814804
required this.tooltipTheme,
815805
// DEPRECATED (newest deprecations at the bottom)
816-
@Deprecated(
817-
'Use colorScheme.secondary instead. '
818-
'For more information, consult the migration guide at '
819-
'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
820-
'This feature was deprecated after v2.3.0-0.1.pre.',
821-
)
822-
Color? accentColor,
823806
@Deprecated(
824807
'This "fix" is now enabled by default. '
825808
'This feature was deprecated after v2.5.0-1.0.pre.',
@@ -865,7 +848,6 @@ class ThemeData with Diagnosticable {
865848

866849
}) : // DEPRECATED (newest deprecations at the bottom)
867850
// should not be `required`, use getter pattern to avoid breakages.
868-
_accentColor = accentColor,
869851
_fixTextFieldOutlineLabel = fixTextFieldOutlineLabel,
870852
_primaryColorBrightness = primaryColorBrightness,
871853
_toggleableActiveColor = toggleableActiveColor,
@@ -875,7 +857,6 @@ class ThemeData with Diagnosticable {
875857
_bottomAppBarColor = bottomAppBarColor,
876858
assert(toggleableActiveColor != null),
877859
// DEPRECATED (newest deprecations at the bottom)
878-
assert(accentColor != null),
879860
assert(fixTextFieldOutlineLabel != null),
880861
assert(primaryColorBrightness != null),
881862
assert(errorColor != null),
@@ -926,7 +907,6 @@ class ThemeData with Diagnosticable {
926907
primaryColor: primarySurfaceColor,
927908
primaryColorBrightness: ThemeData.estimateBrightnessForColor(primarySurfaceColor),
928909
canvasColor: colorScheme.background,
929-
accentColor: colorScheme.secondary,
930910
scaffoldBackgroundColor: colorScheme.background,
931911
bottomAppBarColor: colorScheme.surface,
932912
cardColor: colorScheme.surface,
@@ -1534,25 +1514,6 @@ class ThemeData with Diagnosticable {
15341514

15351515
// DEPRECATED (newest deprecations at the bottom)
15361516

1537-
/// Obsolete property that was originally used as the foreground
1538-
/// color for widgets (knobs, text, overscroll edge effect, etc).
1539-
///
1540-
/// The material library no longer uses this property. In most cases the
1541-
/// [colorScheme]'s [ColorScheme.secondary] property is now used instead.
1542-
///
1543-
/// Apps should migrate uses of this property to the theme's [colorScheme]
1544-
/// [ColorScheme.secondary] color. In cases where a color is needed that
1545-
/// contrasts well with the secondary color [ColorScheme.onSecondary]
1546-
/// can be used.
1547-
@Deprecated(
1548-
'Use colorScheme.secondary instead. '
1549-
'For more information, consult the migration guide at '
1550-
'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
1551-
'This feature was deprecated after v2.3.0-0.1.pre.',
1552-
)
1553-
Color get accentColor => _accentColor!;
1554-
final Color? _accentColor;
1555-
15561517
/// An obsolete flag to allow apps to opt-out of a
15571518
/// [small fix](https://github.com/flutter/flutter/issues/54028) for the Y
15581519
/// coordinate of the floating label in a [TextField] [OutlineInputBorder].
@@ -1737,13 +1698,6 @@ class ThemeData with Diagnosticable {
17371698
ToggleButtonsThemeData? toggleButtonsTheme,
17381699
TooltipThemeData? tooltipTheme,
17391700
// DEPRECATED (newest deprecations at the bottom)
1740-
@Deprecated(
1741-
'No longer used by the framework, please remove any reference to it. '
1742-
'For more information, consult the migration guide at '
1743-
'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
1744-
'This feature was deprecated after v2.3.0-0.1.pre.',
1745-
)
1746-
Color? accentColor,
17471701
@Deprecated(
17481702
'This "fix" is now enabled by default. '
17491703
'This feature was deprecated after v2.5.0-1.0.pre.',
@@ -1877,7 +1831,6 @@ class ThemeData with Diagnosticable {
18771831
toggleButtonsTheme: toggleButtonsTheme ?? this.toggleButtonsTheme,
18781832
tooltipTheme: tooltipTheme ?? this.tooltipTheme,
18791833
// DEPRECATED (newest deprecations at the bottom)
1880-
accentColor: accentColor ?? _accentColor,
18811834
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? _fixTextFieldOutlineLabel,
18821835
primaryColorBrightness: primaryColorBrightness ?? _primaryColorBrightness,
18831836
androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator,
@@ -2071,7 +2024,6 @@ class ThemeData with Diagnosticable {
20712024
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
20722025
tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!,
20732026
// DEPRECATED (newest deprecations at the bottom)
2074-
accentColor: Color.lerp(a.accentColor, b.accentColor, t),
20752027
fixTextFieldOutlineLabel: t < 0.5 ? a.fixTextFieldOutlineLabel : b.fixTextFieldOutlineLabel,
20762028
primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness,
20772029
androidOverscrollIndicator:t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator,
@@ -2177,7 +2129,6 @@ class ThemeData with Diagnosticable {
21772129
other.toggleButtonsTheme == toggleButtonsTheme &&
21782130
other.tooltipTheme == tooltipTheme &&
21792131
// DEPRECATED (newest deprecations at the bottom)
2180-
other.accentColor == accentColor &&
21812132
other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel &&
21822133
other.primaryColorBrightness == primaryColorBrightness &&
21832134
other.androidOverscrollIndicator == androidOverscrollIndicator &&
@@ -2280,7 +2231,6 @@ class ThemeData with Diagnosticable {
22802231
toggleButtonsTheme,
22812232
tooltipTheme,
22822233
// DEPRECATED (newest deprecations at the bottom)
2283-
accentColor,
22842234
fixTextFieldOutlineLabel,
22852235
primaryColorBrightness,
22862236
androidOverscrollIndicator,
@@ -2385,7 +2335,6 @@ class ThemeData with Diagnosticable {
23852335
properties.add(DiagnosticsProperty<ToggleButtonsThemeData>('toggleButtonsTheme', toggleButtonsTheme, level: DiagnosticLevel.debug));
23862336
properties.add(DiagnosticsProperty<TooltipThemeData>('tooltipTheme', tooltipTheme, level: DiagnosticLevel.debug));
23872337
// DEPRECATED (newest deprecations at the bottom)
2388-
properties.add(ColorProperty('accentColor', accentColor, defaultValue: defaultData.accentColor, level: DiagnosticLevel.debug));
23892338
properties.add(DiagnosticsProperty<bool>('fixTextFieldOutlineLabel', fixTextFieldOutlineLabel, level: DiagnosticLevel.debug));
23902339
properties.add(EnumProperty<Brightness>('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug));
23912340
properties.add(EnumProperty<AndroidOverscrollIndicator>('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug));

packages/flutter/test/material/theme_data_test.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ void main() {
186186
expect(theme.primaryColor, theme.colorScheme.primary);
187187
expect(theme.primaryColorBrightness, Brightness.dark);
188188
expect(theme.canvasColor, theme.colorScheme.background);
189-
expect(theme.accentColor, theme.colorScheme.secondary);
190189
expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
191190
expect(theme.bottomAppBarColor, theme.colorScheme.surface);
192191
expect(theme.cardColor, theme.colorScheme.surface);
@@ -237,7 +236,6 @@ void main() {
237236
expect(theme.primaryColor, theme.colorScheme.surface);
238237
expect(theme.primaryColorBrightness, Brightness.dark);
239238
expect(theme.canvasColor, theme.colorScheme.background);
240-
expect(theme.accentColor, theme.colorScheme.secondary);
241239
expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
242240
expect(theme.bottomAppBarColor, theme.colorScheme.surface);
243241
expect(theme.cardColor, theme.colorScheme.surface);
@@ -285,7 +283,6 @@ void main() {
285283
expect(theme.primaryColor, theme.colorScheme.primary);
286284
expect(theme.primaryColorBrightness, Brightness.dark);
287285
expect(theme.canvasColor, theme.colorScheme.background);
288-
expect(theme.accentColor, theme.colorScheme.secondary);
289286
expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
290287
expect(theme.bottomAppBarColor, theme.colorScheme.surface);
291288
expect(theme.cardColor, theme.colorScheme.surface);
@@ -334,7 +331,6 @@ void main() {
334331
expect(theme.primaryColor, theme.colorScheme.primary);
335332
expect(theme.primaryColorBrightness, Brightness.dark);
336333
expect(theme.canvasColor, theme.colorScheme.background);
337-
expect(theme.accentColor, theme.colorScheme.secondary);
338334
expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
339335
expect(theme.bottomAppBarColor, theme.colorScheme.surface);
340336
expect(theme.cardColor, theme.colorScheme.surface);
@@ -383,7 +379,6 @@ void main() {
383379
expect(theme.primaryColor, theme.colorScheme.surface);
384380
expect(theme.primaryColorBrightness, Brightness.dark);
385381
expect(theme.canvasColor, theme.colorScheme.background);
386-
expect(theme.accentColor, theme.colorScheme.secondary);
387382
expect(theme.scaffoldBackgroundColor, theme.colorScheme.background);
388383
expect(theme.bottomAppBarColor, theme.colorScheme.surface);
389384
expect(theme.cardColor, theme.colorScheme.surface);
@@ -401,7 +396,6 @@ void main() {
401396

402397
expect(theme.brightness, equals(Brightness.light));
403398
expect(theme.primaryColor, equals(lightColors.primary));
404-
expect(theme.accentColor, equals(lightColors.secondary));
405399
expect(theme.cardColor, equals(lightColors.surface));
406400
expect(theme.backgroundColor, equals(lightColors.background));
407401
expect(theme.canvasColor, equals(lightColors.background));
@@ -418,7 +412,6 @@ void main() {
418412
expect(theme.brightness, equals(Brightness.dark));
419413
// in dark theme's the color used for main components is surface instead of primary
420414
expect(theme.primaryColor, equals(darkColors.surface));
421-
expect(theme.accentColor, equals(darkColors.secondary));
422415
expect(theme.cardColor, equals(darkColors.surface));
423416
expect(theme.backgroundColor, equals(darkColors.background));
424417
expect(theme.canvasColor, equals(darkColors.background));
@@ -808,7 +801,6 @@ void main() {
808801
toggleButtonsTheme: const ToggleButtonsThemeData(textStyle: TextStyle(color: Colors.black)),
809802
tooltipTheme: const TooltipThemeData(height: 100),
810803
// DEPRECATED (newest deprecations at the bottom)
811-
accentColor: Colors.black,
812804
fixTextFieldOutlineLabel: false,
813805
primaryColorBrightness: Brightness.dark,
814806
androidOverscrollIndicator: AndroidOverscrollIndicator.glow,
@@ -927,7 +919,6 @@ void main() {
927919
tooltipTheme: const TooltipThemeData(height: 100),
928920

929921
// DEPRECATED (newest deprecations at the bottom)
930-
accentColor: Colors.white,
931922
fixTextFieldOutlineLabel: true,
932923
primaryColorBrightness: Brightness.light,
933924
androidOverscrollIndicator: AndroidOverscrollIndicator.stretch,
@@ -1029,7 +1020,6 @@ void main() {
10291020
tooltipTheme: otherTheme.tooltipTheme,
10301021

10311022
// DEPRECATED (newest deprecations at the bottom)
1032-
accentColor: otherTheme.accentColor,
10331023
fixTextFieldOutlineLabel: otherTheme.fixTextFieldOutlineLabel,
10341024
primaryColorBrightness: otherTheme.primaryColorBrightness,
10351025
androidOverscrollIndicator: otherTheme.androidOverscrollIndicator,
@@ -1132,7 +1122,6 @@ void main() {
11321122
expect(themeDataCopy.tooltipTheme, equals(otherTheme.tooltipTheme));
11331123

11341124
// DEPRECATED (newest deprecations at the bottom)
1135-
expect(themeDataCopy.accentColor, equals(otherTheme.accentColor));
11361125
expect(themeDataCopy.fixTextFieldOutlineLabel, equals(otherTheme.fixTextFieldOutlineLabel));
11371126
expect(themeDataCopy.primaryColorBrightness, equals(otherTheme.primaryColorBrightness));
11381127
expect(themeDataCopy.androidOverscrollIndicator, equals(otherTheme.androidOverscrollIndicator));
@@ -1171,7 +1160,6 @@ void main() {
11711160
expect(theme.brightness, equals(Brightness.dark));
11721161
expect(theme.colorScheme.brightness, equals(Brightness.dark));
11731162
expect(theme.primaryColor, equals(lightColors.primary));
1174-
expect(theme.accentColor, equals(lightColors.secondary));
11751163
expect(theme.cardColor, equals(lightColors.surface));
11761164
expect(theme.backgroundColor, equals(lightColors.background));
11771165
expect(theme.canvasColor, equals(lightColors.background));
@@ -1267,7 +1255,6 @@ void main() {
12671255
'toggleButtonsTheme',
12681256
'tooltipTheme',
12691257
// DEPRECATED (newest deprecations at the bottom)
1270-
'accentColor',
12711258
'fixTextFieldOutlineLabel',
12721259
'primaryColorBrightness',
12731260
'androidOverscrollIndicator',

0 commit comments

Comments
 (0)