Skip to content

Commit cdf4a2d

Browse files
authored
Deprecate ThemeData.dialogBackgroundColor in favor of DialogThemeData.backgroundColor (#155072)
Related to [�� Material Theme System Updates](flutter/flutter#91772)
1 parent 5ca6350 commit cdf4a2d

8 files changed

Lines changed: 140 additions & 40 deletions

File tree

packages/flutter/lib/fix_data/fix_material/fix_theme_data.yaml

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,79 @@
2626
# * WidgetState: fix_widget_state.yaml
2727
version: 1
2828
transforms:
29+
# Changes made in https://github.com/flutter/flutter/pull/155072
30+
- title: "Migrate 'ThemeData.dialogBackgroundColor' to 'DialogThemeData.backgroundColor'"
31+
date: 2024-09-12
32+
element:
33+
uris: [ 'material.dart' ]
34+
method: 'copyWith'
35+
inClass: 'ThemeData'
36+
oneOf:
37+
- if: "dialogBackgroundColor != '' && dialogTheme != ''"
38+
changes:
39+
- kind: 'removeParameter'
40+
name: 'dialogBackgroundColor'
41+
- if: "dialogBackgroundColor != '' && dialogTheme == ''"
42+
changes:
43+
- kind: 'removeParameter'
44+
name: 'dialogBackgroundColor'
45+
- kind: 'addParameter'
46+
index: 135
47+
name: 'dialogTheme'
48+
style: optional_named
49+
argumentValue:
50+
expression: 'DialogThemeData(backgroundColor: {% dialogBackgroundColor %})'
51+
requiredIf: "dialogBackgroundColor != ''"
52+
variables:
53+
dialogBackgroundColor:
54+
kind: 'fragment'
55+
value: 'arguments[dialogBackgroundColor]'
56+
dialogTheme:
57+
kind: 'fragment'
58+
value: 'arguments[dialogTheme]'
59+
60+
# Changes made in https://github.com/flutter/flutter/pull/155072
61+
- title: "Migrate 'ThemeData.dialogBackgroundColor' to 'DialogThemeData.backgroundColor'"
62+
date: 2024-09-12
63+
element:
64+
uris: [ 'material.dart' ]
65+
constructor: ''
66+
inClass: 'ThemeData'
67+
oneOf:
68+
- if: "dialogBackgroundColor != '' && dialogTheme != ''"
69+
changes:
70+
- kind: 'removeParameter'
71+
name: 'dialogBackgroundColor'
72+
- if: "dialogBackgroundColor != '' && dialogTheme == ''"
73+
changes:
74+
- kind: 'removeParameter'
75+
name: 'dialogBackgroundColor'
76+
- kind: 'addParameter'
77+
index: 135
78+
name: 'dialogTheme'
79+
style: optional_named
80+
argumentValue:
81+
expression: 'DialogThemeData(backgroundColor: {% dialogBackgroundColor %})'
82+
requiredIf: "dialogBackgroundColor != ''"
83+
variables:
84+
dialogBackgroundColor:
85+
kind: 'fragment'
86+
value: 'arguments[dialogBackgroundColor]'
87+
dialogTheme:
88+
kind: 'fragment'
89+
value: 'arguments[dialogTheme]'
90+
91+
# Changes made in https://github.com/flutter/flutter/pull/145523
92+
- title: "Remove 'buttonBarTheme'"
93+
date: 2024-04-28
94+
element:
95+
uris: [ 'material.dart' ]
96+
constructor: ''
97+
inClass: 'ThemeData'
98+
changes:
99+
- kind: 'removeParameter'
100+
name: 'buttonBarTheme'
101+
29102
# Changes made in https://github.com/flutter/flutter/pull/87281
30103
- title: "Remove 'fixTextFieldOutlineLabel'"
31104
date: 2021-04-30
@@ -1698,15 +1771,4 @@ transforms:
16981771
- kind: 'removeParameter'
16991772
name: 'useMaterial3'
17001773

1701-
# Changes made in https://github.com/flutter/flutter/pull/145523
1702-
- title: "Remove 'buttonBarTheme'"
1703-
date: 2024-04-28
1704-
element:
1705-
uris: [ 'material.dart' ]
1706-
constructor: ''
1707-
inClass: 'ThemeData'
1708-
changes:
1709-
- kind: 'removeParameter'
1710-
name: 'buttonBarTheme'
1711-
17121774
# Before adding a new fix: read instructions at the top of this file.

packages/flutter/lib/fix_data/fix_widgets/fix_widgets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# * ListWheelScrollView: fix_list_wheel_scroll_view.yaml
2424
version: 1
2525
transforms:
26-
# Changes made in TBD
26+
# Changes made in https://github.com/flutter/flutter/pull/139260
2727
- title: "Migrate to focusNode.enclosingScope!"
2828
date: 2023-11-29
2929
element:

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ class Dialog extends StatelessWidget {
9393
///
9494
/// This sets the [Material.color] on this [Dialog]'s [Material].
9595
///
96-
/// If `null`, [ColorScheme.surfaceContainerHigh] is used in Material 3.
97-
/// Otherwise, defaults to [ThemeData.dialogBackgroundColor].
96+
/// If null, then the [DialogThemeData.backgroundColor] is used. If that is
97+
/// also null, defaults to [ColorScheme.surfaceContainerHigh]. If
98+
/// [ThemeData.useMaterial3] is false, defaults to [Colors.grey] with a shade
99+
/// of 800 in dark theme and [Colors.white] in light theme.
98100
///
99101
/// If [Dialog.fullscreen] is used, defaults to [ColorScheme.surface].
100102
/// {@endtemplate}
@@ -1638,33 +1640,34 @@ double _scalePadding(double textScaleFactor) {
16381640
// Hand coded defaults based on Material Design 2.
16391641
class _DialogDefaultsM2 extends DialogThemeData {
16401642
_DialogDefaultsM2(this.context)
1641-
: _textTheme = Theme.of(context).textTheme,
1642-
_iconTheme = Theme.of(context).iconTheme,
1643-
super(
1643+
: super(
16441644
alignment: Alignment.center,
16451645
elevation: 24.0,
16461646
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))),
16471647
clipBehavior: Clip.none,
16481648
);
16491649

16501650
final BuildContext context;
1651-
final TextTheme _textTheme;
1652-
final IconThemeData _iconTheme;
1651+
late final ThemeData theme = Theme.of(context);
1652+
late final TextTheme textTheme = theme.textTheme;
1653+
late final IconThemeData iconTheme = theme.iconTheme;
16531654

16541655
@override
1655-
Color? get iconColor => _iconTheme.color;
1656+
Color? get iconColor => iconTheme.color;
16561657

16571658
@override
1658-
Color? get backgroundColor => Theme.of(context).dialogBackgroundColor;
1659+
Color? get backgroundColor => theme.brightness == Brightness.dark
1660+
? Colors.grey[800]!
1661+
: Colors.white;
16591662

16601663
@override
1661-
Color? get shadowColor => Theme.of(context).shadowColor;
1664+
Color? get shadowColor => theme.shadowColor;
16621665

16631666
@override
1664-
TextStyle? get titleTextStyle => _textTheme.titleLarge;
1667+
TextStyle? get titleTextStyle => textTheme.titleLarge;
16651668

16661669
@override
1667-
TextStyle? get contentTextStyle => _textTheme.titleMedium;
1670+
TextStyle? get contentTextStyle => textTheme.titleMedium;
16681671

16691672
@override
16701673
EdgeInsetsGeometry? get actionsPadding => EdgeInsets.zero;

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

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ class ThemeData with Diagnosticable {
280280
// https://github.com/flutter/flutter/issues/91772.
281281
Color? canvasColor,
282282
Color? cardColor,
283-
Color? dialogBackgroundColor,
284283
Color? disabledColor,
285284
Color? dividerColor,
286285
Color? focusColor,
@@ -361,6 +360,11 @@ class ThemeData with Diagnosticable {
361360
'This feature was deprecated after v3.21.0-10.0.pre.',
362361
)
363362
ButtonBarThemeData? buttonBarTheme,
363+
@Deprecated(
364+
'Use DialogThemeData.backgroundColor instead. '
365+
'This feature was deprecated after v3.27.0-0.1.pre.',
366+
)
367+
Color? dialogBackgroundColor,
364368
}) {
365369
// GENERAL CONFIGURATION
366370
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
@@ -446,7 +450,6 @@ class ThemeData with Diagnosticable {
446450
unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
447451
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
448452
secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!;
449-
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
450453
indicatorColor ??= colorScheme.secondary == primaryColor ? Colors.white : colorScheme.secondary;
451454
hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6);
452455
// The default [buttonTheme] is here because it doesn't use the defaults for
@@ -558,6 +561,7 @@ class ThemeData with Diagnosticable {
558561
tooltipTheme ??= const TooltipThemeData();
559562
// DEPRECATED (newest deprecations at the bottom)
560563
buttonBarTheme ??= const ButtonBarThemeData();
564+
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
561565
return ThemeData.raw(
562566
// For the sanity of the reader, make sure these properties are in the same
563567
// order in every place that they are separated by section comments (e.g.
@@ -581,7 +585,6 @@ class ThemeData with Diagnosticable {
581585
canvasColor: canvasColor,
582586
cardColor: cardColor,
583587
colorScheme: colorScheme,
584-
dialogBackgroundColor: dialogBackgroundColor,
585588
disabledColor: disabledColor,
586589
dividerColor: dividerColor,
587590
focusColor: focusColor,
@@ -651,6 +654,7 @@ class ThemeData with Diagnosticable {
651654
tooltipTheme: tooltipTheme,
652655
// DEPRECATED (newest deprecations at the bottom)
653656
buttonBarTheme: buttonBarTheme,
657+
dialogBackgroundColor: dialogBackgroundColor,
654658
);
655659
}
656660

@@ -687,7 +691,6 @@ class ThemeData with Diagnosticable {
687691
// https://github.com/flutter/flutter/issues/91772.
688692
required this.canvasColor,
689693
required this.cardColor,
690-
required this.dialogBackgroundColor,
691694
required this.disabledColor,
692695
required this.dividerColor,
693696
required this.focusColor,
@@ -761,6 +764,11 @@ class ThemeData with Diagnosticable {
761764
'This feature was deprecated after v3.21.0-10.0.pre.',
762765
)
763766
ButtonBarThemeData? buttonBarTheme,
767+
@Deprecated(
768+
'Use DialogThemeData.backgroundColor instead. '
769+
'This feature was deprecated after v3.27.0-0.1.pre.',
770+
)
771+
required this.dialogBackgroundColor,
764772
}) : // DEPRECATED (newest deprecations at the bottom)
765773
// should not be `required`, use getter pattern to avoid breakages.
766774
_buttonBarTheme = buttonBarTheme,
@@ -1154,9 +1162,6 @@ class ThemeData with Diagnosticable {
11541162
/// backwards compatibility breaks.
11551163
final ColorScheme colorScheme;
11561164

1157-
/// The background color of [Dialog] elements.
1158-
final Color dialogBackgroundColor;
1159-
11601165
/// The color used for widgets that are inoperative, regardless of
11611166
/// their state. For example, a disabled checkbox (which may be
11621167
/// checked or unchecked).
@@ -1424,6 +1429,13 @@ class ThemeData with Diagnosticable {
14241429
ButtonBarThemeData get buttonBarTheme => _buttonBarTheme!;
14251430
final ButtonBarThemeData? _buttonBarTheme;
14261431

1432+
/// The background color of [Dialog] elements.
1433+
@Deprecated(
1434+
'Use DialogThemeData.backgroundColor instead. '
1435+
'This feature was deprecated after v3.27.0-0.1.pre.',
1436+
)
1437+
final Color dialogBackgroundColor;
1438+
14271439
/// Creates a copy of this theme but with the given fields replaced with the new values.
14281440
///
14291441
/// The [brightness] value is applied to the [colorScheme].
@@ -1453,7 +1465,6 @@ class ThemeData with Diagnosticable {
14531465
// https://github.com/flutter/flutter/issues/91772.
14541466
Color? canvasColor,
14551467
Color? cardColor,
1456-
Color? dialogBackgroundColor,
14571468
Color? disabledColor,
14581469
Color? dividerColor,
14591470
Color? focusColor,
@@ -1537,6 +1548,11 @@ class ThemeData with Diagnosticable {
15371548
'This feature was deprecated after v3.21.0-10.0.pre.',
15381549
)
15391550
ButtonBarThemeData? buttonBarTheme,
1551+
@Deprecated(
1552+
'Use DialogThemeData.backgroundColor instead. '
1553+
'This feature was deprecated after v3.27.0-0.1.pre.',
1554+
)
1555+
Color? dialogBackgroundColor,
15401556
}) {
15411557
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
15421558

@@ -1591,7 +1607,6 @@ class ThemeData with Diagnosticable {
15911607
canvasColor: canvasColor ?? this.canvasColor,
15921608
cardColor: cardColor ?? this.cardColor,
15931609
colorScheme: (colorScheme ?? this.colorScheme).copyWith(brightness: brightness),
1594-
dialogBackgroundColor: dialogBackgroundColor ?? this.dialogBackgroundColor,
15951610
disabledColor: disabledColor ?? this.disabledColor,
15961611
dividerColor: dividerColor ?? this.dividerColor,
15971612
focusColor: focusColor ?? this.focusColor,
@@ -1659,7 +1674,9 @@ class ThemeData with Diagnosticable {
16591674
timePickerTheme: timePickerTheme ?? this.timePickerTheme,
16601675
toggleButtonsTheme: toggleButtonsTheme ?? this.toggleButtonsTheme,
16611676
tooltipTheme: tooltipTheme ?? this.tooltipTheme,
1677+
// DEPRECATED (newest deprecations at the bottom)
16621678
buttonBarTheme: buttonBarTheme ?? _buttonBarTheme,
1679+
dialogBackgroundColor: dialogBackgroundColor ?? this.dialogBackgroundColor,
16631680
);
16641681
}
16651682

@@ -1784,7 +1801,6 @@ class ThemeData with Diagnosticable {
17841801
canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t)!,
17851802
cardColor: Color.lerp(a.cardColor, b.cardColor, t)!,
17861803
colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),
1787-
dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t)!,
17881804
disabledColor: Color.lerp(a.disabledColor, b.disabledColor, t)!,
17891805
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t)!,
17901806
focusColor: Color.lerp(a.focusColor, b.focusColor, t)!,
@@ -1852,7 +1868,9 @@ class ThemeData with Diagnosticable {
18521868
timePickerTheme: TimePickerThemeData.lerp(a.timePickerTheme, b.timePickerTheme, t),
18531869
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
18541870
tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!,
1871+
// DEPRECATED (newest deprecations at the bottom)
18551872
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t),
1873+
dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t)!,
18561874
);
18571875
}
18581876

@@ -1884,7 +1902,6 @@ class ThemeData with Diagnosticable {
18841902
other.canvasColor == canvasColor &&
18851903
other.cardColor == cardColor &&
18861904
other.colorScheme == colorScheme &&
1887-
other.dialogBackgroundColor == dialogBackgroundColor &&
18881905
other.disabledColor == disabledColor &&
18891906
other.dividerColor == dividerColor &&
18901907
other.focusColor == focusColor &&
@@ -1952,7 +1969,9 @@ class ThemeData with Diagnosticable {
19521969
other.timePickerTheme == timePickerTheme &&
19531970
other.toggleButtonsTheme == toggleButtonsTheme &&
19541971
other.tooltipTheme == tooltipTheme &&
1955-
other.buttonBarTheme == buttonBarTheme;
1972+
// DEPRECATED (newest deprecations at the bottom)
1973+
other.buttonBarTheme == buttonBarTheme &&
1974+
other.dialogBackgroundColor == dialogBackgroundColor;
19561975
}
19571976

19581977
@override
@@ -1982,7 +2001,6 @@ class ThemeData with Diagnosticable {
19822001
canvasColor,
19832002
cardColor,
19842003
colorScheme,
1985-
dialogBackgroundColor,
19862004
disabledColor,
19872005
dividerColor,
19882006
focusColor,
@@ -2052,6 +2070,7 @@ class ThemeData with Diagnosticable {
20522070
tooltipTheme,
20532071
// DEPRECATED (newest deprecations at the bottom)
20542072
buttonBarTheme,
2073+
dialogBackgroundColor,
20552074
];
20562075
return Object.hashAll(values);
20572076
}
@@ -2082,7 +2101,6 @@ class ThemeData with Diagnosticable {
20822101
properties.add(ColorProperty('canvasColor', canvasColor, defaultValue: defaultData.canvasColor, level: DiagnosticLevel.debug));
20832102
properties.add(ColorProperty('cardColor', cardColor, defaultValue: defaultData.cardColor, level: DiagnosticLevel.debug));
20842103
properties.add(DiagnosticsProperty<ColorScheme>('colorScheme', colorScheme, defaultValue: defaultData.colorScheme, level: DiagnosticLevel.debug));
2085-
properties.add(ColorProperty('dialogBackgroundColor', dialogBackgroundColor, defaultValue: defaultData.dialogBackgroundColor, level: DiagnosticLevel.debug));
20862104
properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: defaultData.disabledColor, level: DiagnosticLevel.debug));
20872105
properties.add(ColorProperty('dividerColor', dividerColor, defaultValue: defaultData.dividerColor, level: DiagnosticLevel.debug));
20882106
properties.add(ColorProperty('focusColor', focusColor, defaultValue: defaultData.focusColor, level: DiagnosticLevel.debug));
@@ -2152,6 +2170,7 @@ class ThemeData with Diagnosticable {
21522170
properties.add(DiagnosticsProperty<TooltipThemeData>('tooltipTheme', tooltipTheme, level: DiagnosticLevel.debug));
21532171
// DEPRECATED (newest deprecations at the bottom)
21542172
properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug));
2173+
properties.add(ColorProperty('dialogBackgroundColor', dialogBackgroundColor, defaultValue: defaultData.dialogBackgroundColor, level: DiagnosticLevel.debug));
21552174
}
21562175
}
21572176

packages/flutter/test_fixes/material/theme_data.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,12 @@ void main() {
237237

238238
// Changes made in https://github.com/flutter/flutter/pull/131455
239239
ThemeData themeData = ThemeData.copyWith(useMaterial3: false);
240+
241+
// Changes made in https://github.com/flutter/flutter/pull/155072
242+
ThemeData themeData = ThemeData();
243+
themeData = ThemeData(dialogBackgroundColor: Colors.orange);
244+
themeData = ThemeData(dialogBackgroundColor: Colors.orange, dialogTheme: DialogThemeData(backgroundColor: Colors.red));
245+
themeData = themeData.copyWith(dialogBackgroundColor: Colors.orange);
246+
themeData = themeData.copyWith(dialogBackgroundColor: Colors.orange, dialogTheme: DialogThemeData(backgroundColor: Colors.red));
247+
themeData.dialogBackgroundColor; // Removing field reference not supported.
240248
}

packages/flutter/test_fixes/material/theme_data.dart.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,12 @@ void main() {
443443

444444
// Changes made in https://github.com/flutter/flutter/pull/131455
445445
ThemeData themeData = ThemeData.copyWith();
446+
447+
// Changes made in https://github.com/flutter/flutter/pull/155072
448+
ThemeData themeData = ThemeData();
449+
themeData = ThemeData(dialogTheme: DialogThemeData(backgroundColor: Colors.orange));
450+
themeData = ThemeData(dialogTheme: DialogThemeData(backgroundColor: Colors.red));
451+
themeData = themeData.copyWith(dialogTheme: DialogThemeData(backgroundColor: Colors.orange));
452+
themeData = themeData.copyWith(dialogTheme: DialogThemeData(backgroundColor: Colors.red));
453+
themeData.dialogBackgroundColor; // Removing field reference not supported.
446454
}

0 commit comments

Comments
 (0)