Skip to content

Commit

Permalink
Deprecate ThemeData accentColor, accentColorBright, accentIconTheme, …
Browse files Browse the repository at this point in the history
…accentTextTheme (#81336)
  • Loading branch information
HansMuller committed Apr 30, 2021
1 parent 5db8f0e commit 8c45386
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 33 deletions.
99 changes: 84 additions & 15 deletions packages/flutter/lib/src/material/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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].
Expand Down Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions packages/flutter/test/material/theme_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8c45386

Please sign in to comment.