Change default value of effectiveInactivePressedOverlayColor in Switch to refer to effectiveInactiveThumbColor (#108477)

This commit is contained in:
Qun Cheng 2022-07-28 09:07:09 -07:00 committed by GitHub
parent 573bd3a025
commit 8a8ed75d3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -751,7 +751,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
final Set<MaterialState> inactivePressedStates = inactiveStates..add(MaterialState.pressed); final Set<MaterialState> inactivePressedStates = inactiveStates..add(MaterialState.pressed);
final Color effectiveInactivePressedOverlayColor = widget.overlayColor?.resolve(inactivePressedStates) final Color effectiveInactivePressedOverlayColor = widget.overlayColor?.resolve(inactivePressedStates)
?? switchTheme.overlayColor?.resolve(inactivePressedStates) ?? switchTheme.overlayColor?.resolve(inactivePressedStates)
?? effectiveActiveThumbColor.withAlpha(kRadialReactionAlpha); ?? effectiveInactiveThumbColor.withAlpha(kRadialReactionAlpha);
final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) { final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) {
return MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states) return MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states)

View File

@ -1552,7 +1552,8 @@ void main() {
final FocusNode focusNode = FocusNode(debugLabel: 'Switch'); final FocusNode focusNode = FocusNode(debugLabel: 'Switch');
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
const Color thumbColor = Color(0xFF000000); const Color activeThumbColor = Color(0xFF000000);
const Color inactiveThumbColor = Color(0xFF000010);
const Color activePressedOverlayColor = Color(0xFF000001); const Color activePressedOverlayColor = Color(0xFF000001);
const Color inactivePressedOverlayColor = Color(0xFF000002); const Color inactivePressedOverlayColor = Color(0xFF000002);
const Color hoverOverlayColor = Color(0xFF000003); const Color hoverOverlayColor = Color(0xFF000003);
@ -1585,7 +1586,12 @@ void main() {
autofocus: focused, autofocus: focused,
value: active, value: active,
onChanged: (_) { }, onChanged: (_) { },
thumbColor: const MaterialStatePropertyAll<Color>(thumbColor), thumbColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return activeThumbColor;
}
return inactiveThumbColor;
}),
overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null,
hoverColor: hoverColor, hoverColor: hoverColor,
focusColor: focusColor, focusColor: focusColor,
@ -1595,6 +1601,7 @@ void main() {
); );
} }
// test inactive Switch, and overlayColor is set to null.
await tester.pumpWidget(buildSwitch(useOverlay: false)); await tester.pumpWidget(buildSwitch(useOverlay: false));
await tester.press(find.byType(Switch)); await tester.press(find.byType(Switch));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@ -1604,12 +1611,13 @@ void main() {
paints paints
..rrect() ..rrect()
..circle( ..circle(
color: thumbColor.withAlpha(kRadialReactionAlpha), color: inactiveThumbColor.withAlpha(kRadialReactionAlpha),
radius: splashRadius, radius: splashRadius,
), ),
reason: 'Default inactive pressed Switch should have overlay color from thumbColor', reason: 'Default inactive pressed Switch should have overlay color from thumbColor',
); );
// test active Switch, and overlayColor is set to null.
await tester.pumpWidget(buildSwitch(active: true, useOverlay: false)); await tester.pumpWidget(buildSwitch(active: true, useOverlay: false));
await tester.press(find.byType(Switch)); await tester.press(find.byType(Switch));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@ -1619,12 +1627,13 @@ void main() {
paints paints
..rrect() ..rrect()
..circle( ..circle(
color: thumbColor.withAlpha(kRadialReactionAlpha), color: activeThumbColor.withAlpha(kRadialReactionAlpha),
radius: splashRadius, radius: splashRadius,
), ),
reason: 'Default active pressed Switch should have overlay color from thumbColor', reason: 'Default active pressed Switch should have overlay color from thumbColor',
); );
// test inactive Switch with an overlayColor
await tester.pumpWidget(buildSwitch()); await tester.pumpWidget(buildSwitch());
await tester.press(find.byType(Switch)); await tester.press(find.byType(Switch));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@ -1640,6 +1649,7 @@ void main() {
reason: 'Inactive pressed Switch should have overlay color: $inactivePressedOverlayColor', reason: 'Inactive pressed Switch should have overlay color: $inactivePressedOverlayColor',
); );
// test active Switch with an overlayColor
await tester.pumpWidget(buildSwitch(active: true)); await tester.pumpWidget(buildSwitch(active: true));
await tester.press(find.byType(Switch)); await tester.press(find.byType(Switch));
await tester.pumpAndSettle(); await tester.pumpAndSettle();