Skip to content

Commit 7130981

Browse files
Migrate more files to use WidgetStateProperty (flutter#174176)
Follow up of flutter#174109 ## 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 `///`). - [ ] 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 86281c3 commit 7130981

27 files changed

+308
-363
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ class ListTile extends StatelessWidget {
958958
if (!enabled || (onTap == null && onLongPress == null)) MaterialState.disabled,
959959
};
960960
final MouseCursor effectiveMouseCursor =
961-
MaterialStateProperty.resolveAs<MouseCursor?>(mouseCursor, mouseStates) ??
961+
WidgetStateProperty.resolveAs<MouseCursor?>(mouseCursor, mouseStates) ??
962962
tileTheme.mouseCursor?.resolve(mouseStates) ??
963963
MaterialStateMouseCursor.clickable.resolve(mouseStates);
964964

@@ -1136,7 +1136,7 @@ class ListTile extends StatelessWidget {
11361136
}
11371137
}
11381138

1139-
class _IndividualOverrides extends MaterialStateProperty<Color?> {
1139+
class _IndividualOverrides extends WidgetStateProperty<Color?> {
11401140
_IndividualOverrides({
11411141
this.explicitColor,
11421142
this.enabledColor,
@@ -1152,7 +1152,7 @@ class _IndividualOverrides extends MaterialStateProperty<Color?> {
11521152
@override
11531153
Color? resolve(Set<MaterialState> states) {
11541154
if (explicitColor is MaterialStateColor) {
1155-
return MaterialStateProperty.resolveAs<Color?>(explicitColor, states);
1155+
return WidgetStateProperty.resolveAs<Color?>(explicitColor, states);
11561156
}
11571157
if (states.contains(MaterialState.disabled)) {
11581158
return disabledColor;

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:flutter/rendering.dart';
1616
import 'package:flutter/widgets.dart';
1717

1818
import 'list_tile.dart';
19-
import 'material_state.dart';
2019
import 'theme.dart';
2120
import 'theme_data.dart';
2221

@@ -127,7 +126,7 @@ class ListTileThemeData with Diagnosticable {
127126
final bool? enableFeedback;
128127

129128
/// If specified, overrides the default value of [ListTile.mouseCursor].
130-
final MaterialStateProperty<MouseCursor?>? mouseCursor;
129+
final WidgetStateProperty<MouseCursor?>? mouseCursor;
131130

132131
/// If specified, overrides the default value of [ListTile.visualDensity].
133132
final VisualDensity? visualDensity;
@@ -163,7 +162,7 @@ class ListTileThemeData with Diagnosticable {
163162
double? minLeadingWidth,
164163
double? minTileHeight,
165164
bool? enableFeedback,
166-
MaterialStateProperty<MouseCursor?>? mouseCursor,
165+
WidgetStateProperty<MouseCursor?>? mouseCursor,
167166
bool? isThreeLine,
168167
VisualDensity? visualDensity,
169168
ListTileTitleAlignment? titleAlignment,
@@ -322,7 +321,7 @@ class ListTileThemeData with Diagnosticable {
322321
properties.add(DoubleProperty('minTileHeight', minTileHeight, defaultValue: null));
323322
properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null));
324323
properties.add(
325-
DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>(
324+
DiagnosticsProperty<WidgetStateProperty<MouseCursor?>>(
326325
'mouseCursor',
327326
mouseCursor,
328327
defaultValue: null,
@@ -376,7 +375,7 @@ class ListTileTheme extends InheritedTheme {
376375
Color? tileColor,
377376
Color? selectedTileColor,
378377
bool? enableFeedback,
379-
MaterialStateProperty<MouseCursor?>? mouseCursor,
378+
WidgetStateProperty<MouseCursor?>? mouseCursor,
380379
double? horizontalTitleGap,
381380
double? minVerticalPadding,
382381
double? minLeadingWidth,
@@ -430,7 +429,7 @@ class ListTileTheme extends InheritedTheme {
430429
final double? _minVerticalPadding;
431430
final double? _minLeadingWidth;
432431
final bool? _enableFeedback;
433-
final MaterialStateProperty<MouseCursor?>? _mouseCursor;
432+
final WidgetStateProperty<MouseCursor?>? _mouseCursor;
434433
final ListTileControlAffinity? _controlAffinity;
435434

436435
/// The configuration of this theme.
@@ -579,7 +578,7 @@ class ListTileTheme extends InheritedTheme {
579578
double? minLeadingWidth,
580579
double? minTileHeight,
581580
ListTileTitleAlignment? titleAlignment,
582-
MaterialStateProperty<MouseCursor?>? mouseCursor,
581+
WidgetStateProperty<MouseCursor?>? mouseCursor,
583582
VisualDensity? visualDensity,
584583
ListTileControlAffinity? controlAffinity,
585584
bool? isThreeLine,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import 'material_state.dart';
5353
@optionalTypeArgs
5454
mixin MaterialStateMixin<T extends StatefulWidget> on State<T> {
5555
/// Managed set of active [MaterialState] values; designed to be passed to
56-
/// [MaterialStateProperty.resolve] methods.
56+
/// [WidgetStateProperty.resolve] methods.
5757
///
5858
/// To mutate and have [setState] called automatically for you, use
5959
/// [setMaterialState], [addMaterialState], or [removeMaterialState]. Directly

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ class SubmenuButton extends StatefulWidget {
15211521
/// If this is null, then the value of [MenuThemeData.submenuIcon] is used.
15221522
/// If that is also null, then defaults to a right arrow icon with the size
15231523
/// of 24 pixels.
1524-
final MaterialStateProperty<Widget?>? submenuIcon;
1524+
final WidgetStateProperty<Widget?>? submenuIcon;
15251525

15261526
/// An optional icon to display after the [child].
15271527
final Widget? trailingIcon;
@@ -1907,7 +1907,7 @@ class _SubmenuButtonState extends State<SubmenuButton> {
19071907
}
19081908

19091909
EdgeInsets _computeMenuPadding(BuildContext context) {
1910-
final MaterialStateProperty<EdgeInsetsGeometry?> insets =
1910+
final WidgetStateProperty<EdgeInsetsGeometry?> insets =
19111911
widget.menuStyle?.padding ??
19121912
MenuTheme.of(context).style?.padding ??
19131913
_MenuDefaultsM3(context).padding!;
@@ -3151,7 +3151,7 @@ class _MenuPanelState extends State<_MenuPanel> {
31513151
return getProperty(widgetStyle) ?? getProperty(themeStyle) ?? getProperty(defaultStyle);
31523152
}
31533153

3154-
T? resolve<T>(MaterialStateProperty<T>? Function(MenuStyle? style) getProperty) {
3154+
T? resolve<T>(WidgetStateProperty<T>? Function(MenuStyle? style) getProperty) {
31553155
return effectiveValue((MenuStyle? style) {
31563156
return getProperty(style)?.resolve(<MaterialState>{});
31573157
});
@@ -3314,7 +3314,7 @@ class _Submenu extends StatelessWidget {
33143314
return getProperty(menuStyle) ?? getProperty(themeStyle) ?? getProperty(defaultStyle);
33153315
}
33163316

3317-
T? resolve<T>(MaterialStateProperty<T>? Function(MenuStyle? style) getProperty) {
3317+
T? resolve<T>(WidgetStateProperty<T>? Function(MenuStyle? style) getProperty) {
33183318
return effectiveValue((MenuStyle? style) {
33193319
return getProperty(style)?.resolve(<MaterialState>{});
33203320
});

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

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,30 @@ class MenuStyle with Diagnosticable {
122122
});
123123

124124
/// The menu's background fill color.
125-
final MaterialStateProperty<Color?>? backgroundColor;
125+
final WidgetStateProperty<Color?>? backgroundColor;
126126

127127
/// The shadow color of the menu's [Material].
128128
///
129129
/// The material's elevation shadow can be difficult to see for dark themes,
130130
/// so by default the menu classes add a semi-transparent overlay to indicate
131131
/// elevation. See [ThemeData.applyElevationOverlayColor].
132-
final MaterialStateProperty<Color?>? shadowColor;
132+
final WidgetStateProperty<Color?>? shadowColor;
133133

134134
/// The surface tint color of the menu's [Material].
135135
///
136136
/// See [Material.surfaceTintColor] for more details.
137-
final MaterialStateProperty<Color?>? surfaceTintColor;
137+
final WidgetStateProperty<Color?>? surfaceTintColor;
138138

139139
/// The elevation of the menu's [Material].
140-
final MaterialStateProperty<double?>? elevation;
140+
final WidgetStateProperty<double?>? elevation;
141141

142142
/// The padding between the menu's boundary and its child.
143-
final MaterialStateProperty<EdgeInsetsGeometry?>? padding;
143+
final WidgetStateProperty<EdgeInsetsGeometry?>? padding;
144144

145145
/// The minimum size of the menu itself.
146146
///
147147
/// This value must be less than or equal to [maximumSize].
148-
final MaterialStateProperty<Size?>? minimumSize;
148+
final WidgetStateProperty<Size?>? minimumSize;
149149

150150
/// The menu's size.
151151
///
@@ -156,31 +156,31 @@ class MenuStyle with Diagnosticable {
156156
/// To specify menus with a fixed width and the default height use `fixedSize:
157157
/// Size.fromWidth(320)`. Similarly, to specify a fixed height and the default
158158
/// width use `fixedSize: Size.fromHeight(100)`.
159-
final MaterialStateProperty<Size?>? fixedSize;
159+
final WidgetStateProperty<Size?>? fixedSize;
160160

161161
/// The maximum size of the menu itself.
162162
///
163163
/// A [Size.infinite] or null value for this property means that the menu's
164164
/// maximum size is not constrained.
165165
///
166166
/// This value must be greater than or equal to [minimumSize].
167-
final MaterialStateProperty<Size?>? maximumSize;
167+
final WidgetStateProperty<Size?>? maximumSize;
168168

169169
/// The color and weight of the menu's outline.
170170
///
171171
/// This value is combined with [shape] to create a shape decorated with an
172172
/// outline.
173-
final MaterialStateProperty<BorderSide?>? side;
173+
final WidgetStateProperty<BorderSide?>? side;
174174

175175
/// The shape of the menu's underlying [Material].
176176
///
177177
/// This shape is combined with [side] to create a shape decorated with an
178178
/// outline.
179-
final MaterialStateProperty<OutlinedBorder?>? shape;
179+
final WidgetStateProperty<OutlinedBorder?>? shape;
180180

181181
/// The cursor for a mouse pointer when it enters or is hovering over this
182182
/// menu's [InkWell].
183-
final MaterialStateProperty<MouseCursor?>? mouseCursor;
183+
final WidgetStateProperty<MouseCursor?>? mouseCursor;
184184

185185
/// Defines how compact the menu's layout will be.
186186
///
@@ -250,17 +250,17 @@ class MenuStyle with Diagnosticable {
250250
/// Returns a copy of this MenuStyle with the given fields replaced with
251251
/// the new values.
252252
MenuStyle copyWith({
253-
MaterialStateProperty<Color?>? backgroundColor,
254-
MaterialStateProperty<Color?>? shadowColor,
255-
MaterialStateProperty<Color?>? surfaceTintColor,
256-
MaterialStateProperty<double?>? elevation,
257-
MaterialStateProperty<EdgeInsetsGeometry?>? padding,
258-
MaterialStateProperty<Size?>? minimumSize,
259-
MaterialStateProperty<Size?>? fixedSize,
260-
MaterialStateProperty<Size?>? maximumSize,
261-
MaterialStateProperty<BorderSide?>? side,
262-
MaterialStateProperty<OutlinedBorder?>? shape,
263-
MaterialStateProperty<MouseCursor?>? mouseCursor,
253+
WidgetStateProperty<Color?>? backgroundColor,
254+
WidgetStateProperty<Color?>? shadowColor,
255+
WidgetStateProperty<Color?>? surfaceTintColor,
256+
WidgetStateProperty<double?>? elevation,
257+
WidgetStateProperty<EdgeInsetsGeometry?>? padding,
258+
WidgetStateProperty<Size?>? minimumSize,
259+
WidgetStateProperty<Size?>? fixedSize,
260+
WidgetStateProperty<Size?>? maximumSize,
261+
WidgetStateProperty<BorderSide?>? side,
262+
WidgetStateProperty<OutlinedBorder?>? shape,
263+
WidgetStateProperty<MouseCursor?>? mouseCursor,
264264
VisualDensity? visualDensity,
265265
AlignmentGeometry? alignment,
266266
}) {
@@ -313,41 +313,31 @@ class MenuStyle with Diagnosticable {
313313
return a;
314314
}
315315
return MenuStyle(
316-
backgroundColor: MaterialStateProperty.lerp<Color?>(
316+
backgroundColor: WidgetStateProperty.lerp<Color?>(
317317
a?.backgroundColor,
318318
b?.backgroundColor,
319319
t,
320320
Color.lerp,
321321
),
322-
shadowColor: MaterialStateProperty.lerp<Color?>(
323-
a?.shadowColor,
324-
b?.shadowColor,
325-
t,
326-
Color.lerp,
327-
),
328-
surfaceTintColor: MaterialStateProperty.lerp<Color?>(
322+
shadowColor: WidgetStateProperty.lerp<Color?>(a?.shadowColor, b?.shadowColor, t, Color.lerp),
323+
surfaceTintColor: WidgetStateProperty.lerp<Color?>(
329324
a?.surfaceTintColor,
330325
b?.surfaceTintColor,
331326
t,
332327
Color.lerp,
333328
),
334-
elevation: MaterialStateProperty.lerp<double?>(a?.elevation, b?.elevation, t, lerpDouble),
335-
padding: MaterialStateProperty.lerp<EdgeInsetsGeometry?>(
329+
elevation: WidgetStateProperty.lerp<double?>(a?.elevation, b?.elevation, t, lerpDouble),
330+
padding: WidgetStateProperty.lerp<EdgeInsetsGeometry?>(
336331
a?.padding,
337332
b?.padding,
338333
t,
339334
EdgeInsetsGeometry.lerp,
340335
),
341-
minimumSize: MaterialStateProperty.lerp<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp),
342-
fixedSize: MaterialStateProperty.lerp<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp),
343-
maximumSize: MaterialStateProperty.lerp<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp),
336+
minimumSize: WidgetStateProperty.lerp<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp),
337+
fixedSize: WidgetStateProperty.lerp<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp),
338+
maximumSize: WidgetStateProperty.lerp<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp),
344339
side: MaterialStateBorderSide.lerp(a?.side, b?.side, t),
345-
shape: MaterialStateProperty.lerp<OutlinedBorder?>(
346-
a?.shape,
347-
b?.shape,
348-
t,
349-
OutlinedBorder.lerp,
350-
),
340+
shape: WidgetStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp),
351341
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,
352342
visualDensity: t < 0.5 ? a?.visualDensity : b?.visualDensity,
353343
alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t),
@@ -358,69 +348,61 @@ class MenuStyle with Diagnosticable {
358348
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
359349
super.debugFillProperties(properties);
360350
properties.add(
361-
DiagnosticsProperty<MaterialStateProperty<Color?>>(
351+
DiagnosticsProperty<WidgetStateProperty<Color?>>(
362352
'backgroundColor',
363353
backgroundColor,
364354
defaultValue: null,
365355
),
366356
);
367357
properties.add(
368-
DiagnosticsProperty<MaterialStateProperty<Color?>>(
358+
DiagnosticsProperty<WidgetStateProperty<Color?>>(
369359
'shadowColor',
370360
shadowColor,
371361
defaultValue: null,
372362
),
373363
);
374364
properties.add(
375-
DiagnosticsProperty<MaterialStateProperty<Color?>>(
365+
DiagnosticsProperty<WidgetStateProperty<Color?>>(
376366
'surfaceTintColor',
377367
surfaceTintColor,
378368
defaultValue: null,
379369
),
380370
);
381371
properties.add(
382-
DiagnosticsProperty<MaterialStateProperty<double?>>(
383-
'elevation',
384-
elevation,
385-
defaultValue: null,
386-
),
372+
DiagnosticsProperty<WidgetStateProperty<double?>>('elevation', elevation, defaultValue: null),
387373
);
388374
properties.add(
389-
DiagnosticsProperty<MaterialStateProperty<EdgeInsetsGeometry?>>(
375+
DiagnosticsProperty<WidgetStateProperty<EdgeInsetsGeometry?>>(
390376
'padding',
391377
padding,
392378
defaultValue: null,
393379
),
394380
);
395381
properties.add(
396-
DiagnosticsProperty<MaterialStateProperty<Size?>>(
382+
DiagnosticsProperty<WidgetStateProperty<Size?>>(
397383
'minimumSize',
398384
minimumSize,
399385
defaultValue: null,
400386
),
401387
);
402388
properties.add(
403-
DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null),
389+
DiagnosticsProperty<WidgetStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null),
404390
);
405391
properties.add(
406-
DiagnosticsProperty<MaterialStateProperty<Size?>>(
392+
DiagnosticsProperty<WidgetStateProperty<Size?>>(
407393
'maximumSize',
408394
maximumSize,
409395
defaultValue: null,
410396
),
411397
);
412398
properties.add(
413-
DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null),
399+
DiagnosticsProperty<WidgetStateProperty<BorderSide?>>('side', side, defaultValue: null),
414400
);
415401
properties.add(
416-
DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>(
417-
'shape',
418-
shape,
419-
defaultValue: null,
420-
),
402+
DiagnosticsProperty<WidgetStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null),
421403
);
422404
properties.add(
423-
DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>(
405+
DiagnosticsProperty<WidgetStateProperty<MouseCursor?>>(
424406
'mouseCursor',
425407
mouseCursor,
426408
defaultValue: null,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ library;
88
import 'package:flutter/foundation.dart';
99
import 'package:flutter/widgets.dart';
1010

11-
import 'material_state.dart';
1211
import 'menu_anchor.dart';
1312
import 'menu_style.dart';
1413
import 'theme.dart';
@@ -52,7 +51,7 @@ class MenuThemeData with Diagnosticable {
5251
/// * [WidgetState.disabled].
5352
/// * [WidgetState.hovered].
5453
/// * [WidgetState.focused].
55-
final MaterialStateProperty<Widget?>? submenuIcon;
54+
final WidgetStateProperty<Widget?>? submenuIcon;
5655

5756
/// Linearly interpolate between two menu button themes.
5857
static MenuThemeData? lerp(MenuThemeData? a, MenuThemeData? b, double t) {
@@ -84,7 +83,7 @@ class MenuThemeData with Diagnosticable {
8483
super.debugFillProperties(properties);
8584
properties.add(DiagnosticsProperty<MenuStyle>('style', style, defaultValue: null));
8685
properties.add(
87-
DiagnosticsProperty<MaterialStateProperty<Widget?>>(
86+
DiagnosticsProperty<WidgetStateProperty<Widget?>>(
8887
'submenuIcon',
8988
submenuIcon,
9089
defaultValue: null,

0 commit comments

Comments
 (0)