Skip to content

Commit ed0aed7

Browse files
authored
Removed the color field from AppBarTheme (flutter#73732)
1 parent 1b1ec73 commit ed0aed7

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class AppBarTheme with Diagnosticable {
2929
/// Creates a theme that can be used for [ThemeData.appBarTheme].
3030
const AppBarTheme({
3131
this.brightness,
32-
this.color,
33-
this.backgroundColor,
32+
Color? color,
33+
Color? backgroundColor,
3434
this.foregroundColor,
3535
this.elevation,
3636
this.shadowColor,
@@ -43,7 +43,10 @@ class AppBarTheme with Diagnosticable {
4343
this.titleTextStyle,
4444
this.systemOverlayStyle,
4545
this.backwardsCompatibility,
46-
});
46+
}) : assert(
47+
color == null || backgroundColor == null,
48+
'The color and backgroundColor parameters mean the same thing. Only specify one.'),
49+
backgroundColor = backgroundColor ?? color;
4750

4851
/// This property is obsolete, please use [systemOverlayStyle] instead.
4952
///
@@ -65,10 +68,11 @@ class AppBarTheme with Diagnosticable {
6568
/// See also:
6669
///
6770
/// * [backgroundColor], which serves this same purpose
68-
/// as this property, but has a consistent name.
71+
/// as this property, but has a name that's consistent with
72+
/// [AppBar.backgroundColor].
6973
/// * [AppBar.backwardsCompatibility], which forces [AppBar] to depend
7074
/// on this obsolete property.
71-
final Color? color;
75+
Color? get color => backgroundColor;
7276

7377
/// Overrides the default value of [AppBar.backgroundColor] in all
7478
/// descendant [AppBar] widgets.
@@ -79,7 +83,6 @@ class AppBarTheme with Diagnosticable {
7983
/// [AppBar.foregroundColor] in all descendant widgets.
8084
final Color? backgroundColor;
8185

82-
8386
/// Overrides the default value of [AppBar.foregroundColor] in all
8487
/// descendant widgets.
8588
///
@@ -185,10 +188,12 @@ class AppBarTheme with Diagnosticable {
185188
SystemUiOverlayStyle? systemOverlayStyle,
186189
bool? backwardsCompatibility,
187190
}) {
191+
assert(
192+
color == null || backgroundColor == null,
193+
'The color and backgroundColor parameters mean the same thing. Only specify one.');
188194
return AppBarTheme(
189195
brightness: brightness ?? this.brightness,
190-
color: color ?? this.color,
191-
backgroundColor: backgroundColor ?? this.backgroundColor,
196+
backgroundColor: backgroundColor ?? color ?? this.backgroundColor,
192197
foregroundColor: foregroundColor ?? this.foregroundColor,
193198
elevation: elevation ?? this.elevation,
194199
shadowColor: shadowColor ?? this.shadowColor,
@@ -218,7 +223,6 @@ class AppBarTheme with Diagnosticable {
218223
assert(t != null);
219224
return AppBarTheme(
220225
brightness: t < 0.5 ? a?.brightness : b?.brightness,
221-
color: Color.lerp(a?.color, b?.color, t),
222226
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
223227
foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t),
224228
elevation: lerpDouble(a?.elevation, b?.elevation, t),
@@ -239,7 +243,6 @@ class AppBarTheme with Diagnosticable {
239243
int get hashCode {
240244
return hashValues(
241245
brightness,
242-
color,
243246
backgroundColor,
244247
foregroundColor,
245248
elevation,
@@ -264,7 +267,6 @@ class AppBarTheme with Diagnosticable {
264267
return false;
265268
return other is AppBarTheme
266269
&& other.brightness == brightness
267-
&& other.color == color
268270
&& other.backgroundColor == backgroundColor
269271
&& other.foregroundColor == foregroundColor
270272
&& other.elevation == elevation
@@ -284,7 +286,6 @@ class AppBarTheme with Diagnosticable {
284286
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
285287
super.debugFillProperties(properties);
286288
properties.add(DiagnosticsProperty<Brightness>('brightness', brightness, defaultValue: null));
287-
properties.add(ColorProperty('color', color, defaultValue: null));
288289
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null));
289290
properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null));
290291
properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null));

packages/flutter/test/material/app_bar_theme_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void main() {
442442
const AppBarTheme(
443443
backwardsCompatibility: false,
444444
brightness: Brightness.dark,
445-
color: Color(0xff000001),
445+
backgroundColor: Color(0xff000001),
446446
elevation: 8.0,
447447
shadowColor: Color(0xff000002),
448448
centerTitle: true,
@@ -456,7 +456,7 @@ void main() {
456456

457457
expect(description, <String>[
458458
'brightness: Brightness.dark',
459-
'color: Color(0xff000001)',
459+
'backgroundColor: Color(0xff000001)',
460460
'elevation: 8.0',
461461
'shadowColor: Color(0xff000002)',
462462
'centerTitle: true',

0 commit comments

Comments
 (0)