diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 3410da74daa9..8c52484c1eee 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -224,7 +224,15 @@ class ThemeData with Diagnosticable { Brightness? primaryColorBrightness, Color? primaryColorLight, Color? primaryColorDark, + @Deprecated( + 'Use colorScheme.secondary instead. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) Color? accentColor, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) Brightness? accentColorBrightness, Color? canvasColor, Color? shadowColor, @@ -268,6 +276,10 @@ class ThemeData with Diagnosticable { String? fontFamily, TextTheme? textTheme, TextTheme? primaryTextTheme, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) TextTheme? accentTextTheme, InputDecorationTheme? inputDecorationTheme, IconThemeData? iconTheme, @@ -550,7 +562,15 @@ class ThemeData with Diagnosticable { required this.primaryColorDark, required this.canvasColor, required this.shadowColor, + @Deprecated( + 'Use colorScheme.secondary instead. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) required this.accentColor, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) required this.accentColorBrightness, required this.scaffoldBackgroundColor, required this.bottomAppBarColor, @@ -591,10 +611,18 @@ class ThemeData with Diagnosticable { required this.toggleableActiveColor, required this.textTheme, required this.primaryTextTheme, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) required this.accentTextTheme, required this.inputDecorationTheme, required this.iconTheme, required this.primaryIconTheme, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) required this.accentIconTheme, required this.sliderTheme, required this.tabBarTheme, @@ -869,19 +897,35 @@ class ThemeData with Diagnosticable { /// overlay on or off for dark themes. final Color shadowColor; - /// The foreground color for widgets (knobs, text, overscroll edge effect, etc). + /// Obsolete property that was originally used as the foreground + /// color for widgets (knobs, text, overscroll edge effect, etc). /// - /// Accent color is also known as the secondary color. + /// The material library no longer uses this property. In most cases + /// the theme's [colorScheme] [ColorScheme.secondary] property is now + /// used instead. /// - /// The theme's [colorScheme] property contains [ColorScheme.secondary], as - /// well as a color that contrasts well with the secondary color called - /// [ColorScheme.onSecondary]. It might be simpler to just configure an app's - /// visuals in terms of the theme's [colorScheme]. + /// Apps should migrate uses of this property to the theme's [colorScheme] + /// [ColorScheme.secondary] color. In cases where a color is needed that + /// that contrasts well with the secondary color [ColorScheme.onSecondary] + /// can be used. + @Deprecated( + 'Use colorScheme.secondary instead. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) final Color accentColor; - /// The brightness of the [accentColor]. Used to determine the color of text - /// and icons placed on top of the accent color (e.g. the icons on a floating - /// action button). + /// Obsolete property that was originally used to determine the color + /// of text and icons placed on top of the accent color (e.g. the + /// icons on a floating action button). + /// + /// The material library no longer uses this property. The + /// [floatingActionButtonTheme] can be used to configure + /// the appearance of [FloatingActionButton]s. The brightness + /// of any color can be found with [ThemeData.estimateBrightnessForColor]. + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) final Brightness accentColorBrightness; /// The default color of the [Material] that underlies the [Scaffold]. The @@ -931,8 +975,7 @@ class ThemeData with Diagnosticable { final Color selectedRowColor; /// The color used for widgets in their inactive (but enabled) - /// state. For example, an unchecked checkbox. Usually contrasted - /// with the [accentColor]. See also [disabledColor]. + /// state. For example, an unchecked checkbox. See also [disabledColor]. final Color unselectedWidgetColor; /// The color used for widgets that are inoperative, regardless of @@ -1004,7 +1047,25 @@ class ThemeData with Diagnosticable { /// A text theme that contrasts with the primary color. final TextTheme primaryTextTheme; - /// A text theme that contrasts with the accent color. + /// Obsolete property that was originally used when a [TextTheme] + /// that contrasted well with the [accentColor] was needed. + /// + /// The material library no longer uses this property and most uses + /// of [accentColor] have been replaced with + /// the theme's [colorScheme] [ColorScheme.secondary]. + /// You can configure the color of a [textTheme] [TextStyle] so that it + /// contrasts well with the [ColorScheme.secondary] like this: + /// + /// ```dart + /// final ThemeData theme = Theme.of(context); + /// theme.textTheme.headline1.copyWith( + /// color: theme.colorScheme.onSecondary, + /// ) + /// ``` + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) final TextTheme accentTextTheme; /// The default [InputDecoration] values for [InputDecorator], [TextField], @@ -1019,7 +1080,16 @@ class ThemeData with Diagnosticable { /// An icon theme that contrasts with the primary color. final IconThemeData primaryIconTheme; - /// An icon theme that contrasts with the accent color. + /// Obsolete property that was originally used when an [IconTheme] + /// that contrasted well with the [accentColor] was needed. + /// + /// The material library no longer uses this property and most uses + /// of [accentColor] have been replaced with + /// the theme's [colorScheme] [ColorScheme.secondary]. + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.3.0-0.1.pre.', + ) final IconThemeData accentIconTheme; /// The colors and shapes used to render [Slider]. @@ -1146,8 +1216,7 @@ class ThemeData with Diagnosticable { /// icon themes of a [NavigationRail]. final NavigationRailThemeData navigationRailTheme; - /// The color and geometry [TextTheme] values used to configure [textTheme], - /// [primaryTextTheme], and [accentTextTheme]. + /// The color and geometry [TextTheme] values used to configure [textTheme]. final Typography typography; /// Components of the [CupertinoThemeData] to override from the Material diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index 82929fd01a20..a3599ef82257 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -51,15 +51,6 @@ void main() { expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color); }); - test('Default accent text theme contrasts with accent brightness', () { - final ThemeData lightTheme = ThemeData(accentColorBrightness: Brightness.light); - final ThemeData darkTheme = ThemeData(accentColorBrightness: Brightness.dark); - final Typography typography = Typography.material2018(platform: lightTheme.platform); - - expect(lightTheme.accentTextTheme.headline6!.color, typography.black.headline6!.color); - expect(darkTheme.accentTextTheme.headline6!.color, typography.white.headline6!.color); - }); - test('Default chip label style gets a default bodyText1 if textTheme.bodyText1 is null', () { const TextTheme noBodyText1TextTheme = TextTheme(bodyText1: null); final ThemeData lightTheme = ThemeData(brightness: Brightness.light, textTheme: noBodyText1TextTheme); @@ -88,15 +79,6 @@ void main() { expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color); }); - test('Default accent icon theme contrasts with accent brightness', () { - final ThemeData lightTheme = ThemeData(accentColorBrightness: Brightness.light); - final ThemeData darkTheme = ThemeData(accentColorBrightness: Brightness.dark); - final Typography typography = Typography.material2018(platform: lightTheme.platform); - - expect(lightTheme.accentTextTheme.headline6!.color, typography.black.headline6!.color); - expect(darkTheme.accentTextTheme.headline6!.color, typography.white.headline6!.color); - }); - testWidgets('Defaults to MaterialTapTargetBehavior.padded on mobile platforms and MaterialTapTargetBehavior.shrinkWrap on desktop', (WidgetTester tester) async { final ThemeData themeData = ThemeData(platform: defaultTargetPlatform); switch (defaultTargetPlatform) {