Unverified Commit 8a8ed75d authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Change default value of `effectiveInactivePressedOverlayColor` in Switch to...

Change default value of `effectiveInactivePressedOverlayColor` in Switch to refer to `effectiveInactiveThumbColor` (#108477)
parent 573bd3a0
...@@ -751,7 +751,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta ...@@ -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)
......
...@@ -1552,7 +1552,8 @@ void main() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment