Skip to content

Commit

Permalink
Remove ThemeData.buttonColor references (#118658)
Browse files Browse the repository at this point in the history
* Remove ThemeData.buttonColor references

* Fix test

* Remove more buttonColors

* Macro the definition of color scheme

* remove doc reference
  • Loading branch information
gspencergoog authored Jan 24, 2023
1 parent e8b7f4b commit df44208
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 52 deletions.
11 changes: 5 additions & 6 deletions packages/flutter/lib/src/material/button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,12 @@ class ButtonThemeData with Diagnosticable {
/// A set of thirteen colors that can be used to derive the button theme's
/// colors.
///
/// This property was added much later than the theme's set of highly
/// specific colors, like [ThemeData.buttonColor], [ThemeData.highlightColor],
/// [ThemeData.splashColor] etc.
/// This property was added much later than the theme's set of highly specific
/// colors, like [ThemeData.highlightColor] and [ThemeData.splashColor] etc.
///
/// The colors for new button classes can be defined exclusively in terms
/// of [colorScheme]. When it's possible, the existing buttons will
/// (continue to) gradually migrate to it.
/// The colors for new button classes can be defined exclusively in terms of
/// [colorScheme]. When it's possible, the existing buttons will (continue to)
/// gradually migrate to it.
final ColorScheme? colorScheme;

// The minimum size of a button's tap target.
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/material/color_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import 'package:material_color_utilities/material_color_utilities.dart';
import 'colors.dart';
import 'theme_data.dart';

/// {@template flutter.material.color_scheme.ColorScheme}
/// A set of 30 colors based on the
/// [Material spec](https://m3.material.io/styles/color/the-color-system/color-roles)
/// that can be used to configure the color properties of most components.
/// {@endtemplate}
///
/// The main accent color groups in the scheme are [primary], [secondary],
/// and [tertiary].
Expand Down
47 changes: 7 additions & 40 deletions packages/flutter/lib/src/material/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,6 @@ class ThemeData with Diagnosticable {
'This feature was deprecated after v2.3.0-0.1.pre.',
)
IconThemeData? accentIconTheme,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v2.3.0-0.2.pre.',
)
Color? buttonColor,
@Deprecated(
'This "fix" is now enabled by default. '
'This feature was deprecated after v2.5.0-1.0.pre.',
Expand Down Expand Up @@ -552,7 +547,7 @@ class ThemeData with Diagnosticable {
// [disabledColor], [highlightColor], and [splashColor].
buttonTheme ??= ButtonThemeData(
colorScheme: colorScheme,
buttonColor: buttonColor ?? (isDark ? primarySwatch[600]! : Colors.grey[300]!),
buttonColor: isDark ? primarySwatch[600]! : Colors.grey[300]!,
disabledColor: disabledColor,
focusColor: focusColor,
hoverColor: hoverColor,
Expand Down Expand Up @@ -637,7 +632,6 @@ class ThemeData with Diagnosticable {
// DEPRECATED (newest deprecations at the bottom)
accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme);
accentIconTheme ??= accentIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
buttonColor ??= isDark ? primarySwatch[600]! : Colors.grey[300]!;
fixTextFieldOutlineLabel ??= true;
primaryColorBrightness = estimatedPrimaryColorBrightness;
errorColor ??= Colors.red[700]!;
Expand Down Expand Up @@ -736,7 +730,6 @@ class ThemeData with Diagnosticable {
accentColorBrightness: accentColorBrightness,
accentTextTheme: accentTextTheme,
accentIconTheme: accentIconTheme,
buttonColor: buttonColor,
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
primaryColorBrightness: primaryColorBrightness,
androidOverscrollIndicator: androidOverscrollIndicator,
Expand Down Expand Up @@ -874,11 +867,6 @@ class ThemeData with Diagnosticable {
'This feature was deprecated after v2.3.0-0.1.pre.',
)
IconThemeData? accentIconTheme,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v2.3.0-0.2.pre.',
)
Color? buttonColor,
@Deprecated(
'This "fix" is now enabled by default. '
'This feature was deprecated after v2.5.0-1.0.pre.',
Expand Down Expand Up @@ -928,7 +916,6 @@ class ThemeData with Diagnosticable {
_accentColorBrightness = accentColorBrightness,
_accentTextTheme = accentTextTheme,
_accentIconTheme = accentIconTheme,
_buttonColor = buttonColor,
_fixTextFieldOutlineLabel = fixTextFieldOutlineLabel,
_primaryColorBrightness = primaryColorBrightness,
_toggleableActiveColor = toggleableActiveColor,
Expand Down Expand Up @@ -1022,7 +1009,6 @@ class ThemeData with Diagnosticable {
assert(accentColorBrightness != null),
assert(accentTextTheme != null),
assert(accentIconTheme != null),
assert(buttonColor != null),
assert(fixTextFieldOutlineLabel != null),
assert(primaryColorBrightness != null),
assert(errorColor != null),
Expand Down Expand Up @@ -1405,14 +1391,13 @@ class ThemeData with Diagnosticable {
/// The color of [Material] when it is used as a [Card].
final Color cardColor;

/// A set of twelve colors that can be used to configure the
/// color properties of most components.
/// {@macro flutter.material.color_scheme.ColorScheme}
///
/// This property was added much later than the theme's set of highly
/// specific colors, like [cardColor], [buttonColor], [canvasColor] etc.
/// New components can be defined exclusively in terms of [colorScheme].
/// Existing components will gradually migrate to it, to the extent
/// that is possible without significant backwards compatibility breaks.
/// This property was added much later than the theme's set of highly specific
/// colors, like [cardColor], [canvasColor] etc. New components can be defined
/// exclusively in terms of [colorScheme]. Existing components will gradually
/// migrate to it, to the extent that is possible without significant
/// backwards compatibility breaks.
final ColorScheme colorScheme;

/// The background color of [Dialog] elements.
Expand Down Expand Up @@ -1752,14 +1737,6 @@ class ThemeData with Diagnosticable {
IconThemeData get accentIconTheme => _accentIconTheme!;
final IconThemeData? _accentIconTheme;

/// The default fill color of the [Material].
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v2.3.0-0.2.pre.',
)
Color get buttonColor => _buttonColor!;
final Color? _buttonColor;

/// An obsolete flag to allow apps to opt-out of a
/// [small fix](https://github.com/flutter/flutter/issues/54028) for the Y
/// coordinate of the floating label in a [TextField] [OutlineInputBorder].
Expand Down Expand Up @@ -1971,11 +1948,6 @@ class ThemeData with Diagnosticable {
'This feature was deprecated after v2.3.0-0.1.pre.',
)
IconThemeData? accentIconTheme,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v2.3.0-0.2.pre.',
)
Color? buttonColor,
@Deprecated(
'This "fix" is now enabled by default. '
'This feature was deprecated after v2.5.0-1.0.pre.',
Expand Down Expand Up @@ -2112,7 +2084,6 @@ class ThemeData with Diagnosticable {
accentColorBrightness: accentColorBrightness ?? _accentColorBrightness,
accentTextTheme: accentTextTheme ?? _accentTextTheme,
accentIconTheme: accentIconTheme ?? _accentIconTheme,
buttonColor: buttonColor ?? _buttonColor,
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? _fixTextFieldOutlineLabel,
primaryColorBrightness: primaryColorBrightness ?? _primaryColorBrightness,
androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator,
Expand Down Expand Up @@ -2312,7 +2283,6 @@ class ThemeData with Diagnosticable {
accentColorBrightness: t < 0.5 ? a.accentColorBrightness : b.accentColorBrightness,
accentTextTheme: TextTheme.lerp(a.accentTextTheme, b.accentTextTheme, t),
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t),
fixTextFieldOutlineLabel: t < 0.5 ? a.fixTextFieldOutlineLabel : b.fixTextFieldOutlineLabel,
primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness,
androidOverscrollIndicator:t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator,
Expand Down Expand Up @@ -2421,7 +2391,6 @@ class ThemeData with Diagnosticable {
other.accentColorBrightness == accentColorBrightness &&
other.accentTextTheme == accentTextTheme &&
other.accentIconTheme == accentIconTheme &&
other.buttonColor == buttonColor &&
other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel &&
other.primaryColorBrightness == primaryColorBrightness &&
other.androidOverscrollIndicator == androidOverscrollIndicator &&
Expand Down Expand Up @@ -2527,7 +2496,6 @@ class ThemeData with Diagnosticable {
accentColorBrightness,
accentTextTheme,
accentIconTheme,
buttonColor,
fixTextFieldOutlineLabel,
primaryColorBrightness,
androidOverscrollIndicator,
Expand Down Expand Up @@ -2635,7 +2603,6 @@ class ThemeData with Diagnosticable {
properties.add(EnumProperty<Brightness>('accentColorBrightness', accentColorBrightness, defaultValue: defaultData.accentColorBrightness, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<TextTheme>('accentTextTheme', accentTextTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<IconThemeData>('accentIconTheme', accentIconTheme, level: DiagnosticLevel.debug));
properties.add(ColorProperty('buttonColor', buttonColor, defaultValue: defaultData.buttonColor, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<bool>('fixTextFieldOutlineLabel', fixTextFieldOutlineLabel, level: DiagnosticLevel.debug));
properties.add(EnumProperty<Brightness>('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug));
properties.add(EnumProperty<AndroidOverscrollIndicator>('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug));
Expand Down
7 changes: 1 addition & 6 deletions packages/flutter/test/material/theme_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ void main() {
textStyle: TextStyle(fontSize: 100),
);

// Both ThemeDatas include both extensions
// Both ThemeData arguments include both extensions.
ThemeData lerped = ThemeData.lerp(
ThemeData(
extensions: const <ThemeExtension<dynamic>>[
Expand Down Expand Up @@ -816,7 +816,6 @@ void main() {
accentColorBrightness: Brightness.dark,
accentTextTheme: ThemeData.dark().textTheme,
accentIconTheme: ThemeData.dark().iconTheme,
buttonColor: Colors.black,
fixTextFieldOutlineLabel: false,
primaryColorBrightness: Brightness.dark,
androidOverscrollIndicator: AndroidOverscrollIndicator.glow,
Expand Down Expand Up @@ -938,7 +937,6 @@ void main() {
accentColorBrightness: Brightness.light,
accentIconTheme: ThemeData.light().iconTheme,
accentTextTheme: ThemeData.light().textTheme,
buttonColor: Colors.white,
fixTextFieldOutlineLabel: true,
primaryColorBrightness: Brightness.light,
androidOverscrollIndicator: AndroidOverscrollIndicator.stretch,
Expand Down Expand Up @@ -1043,7 +1041,6 @@ void main() {
accentColorBrightness: otherTheme.accentColorBrightness,
accentIconTheme: otherTheme.accentIconTheme,
accentTextTheme: otherTheme.accentTextTheme,
buttonColor: otherTheme.buttonColor,
fixTextFieldOutlineLabel: otherTheme.fixTextFieldOutlineLabel,
primaryColorBrightness: otherTheme.primaryColorBrightness,
androidOverscrollIndicator: otherTheme.androidOverscrollIndicator,
Expand Down Expand Up @@ -1149,7 +1146,6 @@ void main() {
expect(themeDataCopy.accentColorBrightness, equals(otherTheme.accentColorBrightness));
expect(themeDataCopy.accentIconTheme, equals(otherTheme.accentIconTheme));
expect(themeDataCopy.accentTextTheme, equals(otherTheme.accentTextTheme));
expect(themeDataCopy.buttonColor, equals(otherTheme.buttonColor));
expect(themeDataCopy.fixTextFieldOutlineLabel, equals(otherTheme.fixTextFieldOutlineLabel));
expect(themeDataCopy.primaryColorBrightness, equals(otherTheme.primaryColorBrightness));
expect(themeDataCopy.androidOverscrollIndicator, equals(otherTheme.androidOverscrollIndicator));
Expand Down Expand Up @@ -1287,7 +1283,6 @@ void main() {
'accentColorBrightness',
'accentTextTheme',
'accentIconTheme',
'buttonColor',
'fixTextFieldOutlineLabel',
'primaryColorBrightness',
'androidOverscrollIndicator',
Expand Down

0 comments on commit df44208

Please sign in to comment.