Skip to content

Commit e90bd46

Browse files
Make component theme data defaults use WidgetStateProperty (flutter#173893)
Coming from the comments in flutter#173160 (comment) `MaterialStateProperty` is deprecated. This PR remplaces its usage with `WidgetStateProperty` for the files that generates component theme data defaults ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 00d9b6f commit e90bd46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+386
-387
lines changed

dev/benchmarks/macrobenchmarks/lib/src/web/material3.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class _SwitchRowState extends State<SwitchRow> {
718718
bool value0 = false;
719719
bool value1 = true;
720720

721-
final MaterialStateProperty<Icon?> thumbIcon = MaterialStateProperty.resolveWith<Icon?>((
721+
final WidgetStateProperty<Icon?> thumbIcon = WidgetStateProperty.resolveWith<Icon?>((
722722
Set<MaterialState> states,
723723
) {
724724
if (states.contains(MaterialState.selected)) {
@@ -1251,7 +1251,7 @@ ButtonStyle enabledOutlinedButtonStyle(bool selected, ColorScheme colors) {
12511251
: colors.onSurface.withOpacity(0.12),
12521252
side: BorderSide(color: colors.outline),
12531253
).copyWith(
1254-
foregroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
1254+
foregroundColor: WidgetStateProperty.resolveWith((Set<MaterialState> states) {
12551255
if (states.contains(MaterialState.selected)) {
12561256
return colors.onInverseSurface;
12571257
}

dev/integration_tests/new_gallery/lib/themes/material_demo_theme_data.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class MaterialDemoThemeData {
2222
),
2323
bottomAppBarTheme: BottomAppBarThemeData(color: _colorScheme.primary),
2424
checkboxTheme: CheckboxThemeData(
25-
fillColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
25+
fillColor: WidgetStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
2626
if (states.contains(MaterialState.disabled)) {
2727
return null;
2828
}
2929
return states.contains(MaterialState.selected) ? _colorScheme.primary : null;
3030
}),
3131
),
3232
radioTheme: RadioThemeData(
33-
fillColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
33+
fillColor: WidgetStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
3434
if (states.contains(MaterialState.disabled)) {
3535
return null;
3636
}
@@ -39,13 +39,13 @@ class MaterialDemoThemeData {
3939
),
4040
snackBarTheme: const SnackBarThemeData(behavior: SnackBarBehavior.floating),
4141
switchTheme: SwitchThemeData(
42-
thumbColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
42+
thumbColor: WidgetStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
4343
if (states.contains(MaterialState.disabled)) {
4444
return null;
4545
}
4646
return states.contains(MaterialState.selected) ? _colorScheme.primary : null;
4747
}),
48-
trackColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
48+
trackColor: WidgetStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
4949
if (states.contains(MaterialState.disabled)) {
5050
return null;
5151
}

dev/manual_tests/lib/actions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class _DemoButtonState extends State<DemoButton> {
307307
focusNode: _focusNode,
308308
style: ButtonStyle(
309309
foregroundColor: const MaterialStatePropertyAll<Color>(Colors.black),
310-
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
310+
overlayColor: WidgetStateProperty.resolveWith<Color>((Set<MaterialState> states) {
311311
if (states.contains(MaterialState.focused)) {
312312
return Colors.red;
313313
}

dev/manual_tests/lib/focus.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _DemoButtonState extends State<DemoButton> {
5555
focusNode: focusNode,
5656
autofocus: widget.autofocus,
5757
style: ButtonStyle(
58-
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
58+
overlayColor: WidgetStateProperty.resolveWith<Color>((Set<MaterialState> states) {
5959
if (states.contains(MaterialState.focused)) {
6060
return Colors.red.withOpacity(0.25);
6161
}

dev/manual_tests/lib/hover.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class _HoverDemoState extends State<HoverDemo> {
2020
Widget build(BuildContext context) {
2121
final TextTheme textTheme = Theme.of(context).textTheme;
2222
final ButtonStyle overrideFocusColor = ButtonStyle(
23-
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
23+
overlayColor: WidgetStateProperty.resolveWith<Color>((Set<MaterialState> states) {
2424
return states.contains(MaterialState.focused)
2525
? Colors.deepOrangeAccent
2626
: Colors.transparent;

dev/tools/gen_defaults/lib/action_chip_template.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
4949
);
5050
5151
@override
52-
MaterialStateProperty<Color?>? get color =>
53-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
52+
WidgetStateProperty<Color?>? get color =>
53+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
5454
if (states.contains(MaterialState.disabled)) {
5555
return _chipVariant == _ChipVariant.flat
5656
? ${componentColor("$tokenGroup$flatVariant.disabled.container")}

dev/tools/gen_defaults/lib/button_template.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ButtonTemplate extends TokenTemplate {
1919
if (tokenAvailable('$tokenGroup.container.color')) {
2020
return '''
2121
22-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
22+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
2323
if (states.contains(MaterialState.disabled)) {
2424
return ${componentColor('$tokenGroup.disabled.container')};
2525
}
@@ -35,7 +35,7 @@ class ButtonTemplate extends TokenTemplate {
3535
if (tokenAvailable('$tokenGroup.container.elevation')) {
3636
return '''
3737
38-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
38+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
3939
if (states.contains(MaterialState.disabled)) {
4040
return ${elevation("$tokenGroup.disabled.container")};
4141
}
@@ -79,24 +79,24 @@ class _${blockName}DefaultsM3 extends ButtonStyle {
7979
late final ColorScheme _colors = Theme.of(context).colorScheme;
8080
8181
@override
82-
MaterialStateProperty<TextStyle?> get textStyle =>
82+
WidgetStateProperty<TextStyle?> get textStyle =>
8383
MaterialStatePropertyAll<TextStyle?>(${textStyle("$tokenGroup.label-text")});
8484
8585
@override
86-
MaterialStateProperty<Color?>? get backgroundColor =>${_backgroundColor()};
86+
WidgetStateProperty<Color?>? get backgroundColor =>${_backgroundColor()};
8787
8888
@override
89-
MaterialStateProperty<Color?>? get foregroundColor =>
90-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
89+
WidgetStateProperty<Color?>? get foregroundColor =>
90+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
9191
if (states.contains(MaterialState.disabled)) {
9292
return ${componentColor('$tokenGroup.disabled.label-text')};
9393
}
9494
return ${componentColor('$tokenGroup.label-text')};
9595
});
9696
9797
@override
98-
MaterialStateProperty<Color?>? get overlayColor =>
99-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
98+
WidgetStateProperty<Color?>? get overlayColor =>
99+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
100100
if (states.contains(MaterialState.pressed)) {
101101
return ${componentColor('$tokenGroup.pressed.state-layer')};
102102
}
@@ -110,33 +110,33 @@ class _${blockName}DefaultsM3 extends ButtonStyle {
110110
});
111111
112112
@override
113-
MaterialStateProperty<Color>? get shadowColor =>
113+
WidgetStateProperty<Color>? get shadowColor =>
114114
${_elevationColor("$tokenGroup.container.shadow-color")};
115115
116116
@override
117-
MaterialStateProperty<Color>? get surfaceTintColor =>
117+
WidgetStateProperty<Color>? get surfaceTintColor =>
118118
${_elevationColor("$tokenGroup.container.surface-tint-layer.color")};
119119
120120
@override
121-
MaterialStateProperty<double>? get elevation =>${_elevation()};
121+
WidgetStateProperty<double>? get elevation =>${_elevation()};
122122
123123
@override
124-
MaterialStateProperty<EdgeInsetsGeometry>? get padding =>
124+
WidgetStateProperty<EdgeInsetsGeometry>? get padding =>
125125
MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context));
126126
127127
@override
128-
MaterialStateProperty<Size>? get minimumSize =>
128+
WidgetStateProperty<Size>? get minimumSize =>
129129
const MaterialStatePropertyAll<Size>(Size(64.0, ${getToken("$tokenGroup.container.height")}));
130130
131131
// No default fixedSize
132132
133133
@override
134-
MaterialStateProperty<double>? get iconSize =>
134+
WidgetStateProperty<double>? get iconSize =>
135135
const MaterialStatePropertyAll<double>(${getToken("$tokenGroup.with-icon.icon.size")});
136136
137137
@override
138-
MaterialStateProperty<Color>? get iconColor {
139-
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
138+
WidgetStateProperty<Color>? get iconColor {
139+
return WidgetStateProperty.resolveWith((Set<MaterialState> states) {
140140
if (states.contains(MaterialState.disabled)) {
141141
return ${color('$tokenGroup.with-icon.disabled.icon.color')}.withOpacity(${opacity("$tokenGroup.with-icon.disabled.icon.opacity")});
142142
}
@@ -154,13 +154,13 @@ class _${blockName}DefaultsM3 extends ButtonStyle {
154154
}
155155
156156
@override
157-
MaterialStateProperty<Size>? get maximumSize =>
157+
WidgetStateProperty<Size>? get maximumSize =>
158158
const MaterialStatePropertyAll<Size>(Size.infinite);
159159
160160
${tokenAvailable("$tokenGroup.outline.color") ? '''
161161
@override
162-
MaterialStateProperty<BorderSide>? get side =>
163-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
162+
WidgetStateProperty<BorderSide>? get side =>
163+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
164164
if (states.contains(MaterialState.disabled)) {
165165
return ${border("$tokenGroup.disabled.outline")};
166166
}
@@ -172,12 +172,12 @@ ${tokenAvailable("$tokenGroup.outline.color") ? '''
172172
// No default side'''}
173173
174174
@override
175-
MaterialStateProperty<OutlinedBorder>? get shape =>
175+
WidgetStateProperty<OutlinedBorder>? get shape =>
176176
const MaterialStatePropertyAll<OutlinedBorder>(${shape("$tokenGroup.container", '')});
177177
178178
@override
179-
MaterialStateProperty<MouseCursor?>? get mouseCursor =>
180-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
179+
WidgetStateProperty<MouseCursor?>? get mouseCursor =>
180+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
181181
if (states.contains(MaterialState.disabled)) {
182182
return SystemMouseCursors.basic;
183183
}

dev/tools/gen_defaults/lib/checkbox_template.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class _${blockName}DefaultsM3 extends CheckboxThemeData {
5252
}
5353
5454
@override
55-
MaterialStateProperty<Color> get fillColor {
56-
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
55+
WidgetStateProperty<Color> get fillColor {
56+
return WidgetStateProperty.resolveWith((Set<MaterialState> states) {
5757
if (states.contains(MaterialState.disabled)) {
5858
if (states.contains(MaterialState.selected)) {
5959
return ${componentColor('md.comp.checkbox.selected.disabled.container')};
@@ -71,8 +71,8 @@ class _${blockName}DefaultsM3 extends CheckboxThemeData {
7171
}
7272
7373
@override
74-
MaterialStateProperty<Color> get checkColor {
75-
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
74+
WidgetStateProperty<Color> get checkColor {
75+
return WidgetStateProperty.resolveWith((Set<MaterialState> states) {
7676
if (states.contains(MaterialState.disabled)) {
7777
if (states.contains(MaterialState.selected)) {
7878
return ${componentColor('md.comp.checkbox.selected.disabled.icon')};
@@ -90,8 +90,8 @@ class _${blockName}DefaultsM3 extends CheckboxThemeData {
9090
}
9191
9292
@override
93-
MaterialStateProperty<Color> get overlayColor {
94-
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
93+
WidgetStateProperty<Color> get overlayColor {
94+
return WidgetStateProperty.resolveWith((Set<MaterialState> states) {
9595
if (states.contains(MaterialState.error)) {
9696
if (states.contains(MaterialState.pressed)) {
9797
return ${componentColor('md.comp.checkbox.error.pressed.state-layer')};

dev/tools/gen_defaults/lib/chip_template.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
4040
);
4141
4242
@override
43-
MaterialStateProperty<Color?>? get color => null; // Subclasses override this getter
43+
WidgetStateProperty<Color?>? get color => null; // Subclasses override this getter
4444
4545
@override
4646
Color? get shadowColor => ${colorOrTransparent("$tokenGroup.container.shadow-color")};

dev/tools/gen_defaults/lib/filter_chip_template.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
5656
);
5757
5858
@override
59-
MaterialStateProperty<Color?>? get color =>
60-
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
59+
WidgetStateProperty<Color?>? get color =>
60+
WidgetStateProperty.resolveWith((Set<MaterialState> states) {
6161
if (states.contains(MaterialState.selected) && states.contains(MaterialState.disabled)) {
6262
return _chipVariant == _ChipVariant.flat
6363
? ${componentColor("$tokenGroup$flatVariant.disabled.selected.container")}

0 commit comments

Comments
 (0)