From 8a8ed75d3e94326266ed13a8dc748102e400b8fb Mon Sep 17 00:00:00 2001 From: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> Date: Thu, 28 Jul 2022 09:07:09 -0700 Subject: [PATCH] Change default value of `effectiveInactivePressedOverlayColor` in Switch to refer to `effectiveInactiveThumbColor` (#108477) --- packages/flutter/lib/src/material/switch.dart | 2 +- .../flutter/test/material/switch_test.dart | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/material/switch.dart b/packages/flutter/lib/src/material/switch.dart index 7f25310e92..0c0ca3e3bd 100644 --- a/packages/flutter/lib/src/material/switch.dart +++ b/packages/flutter/lib/src/material/switch.dart @@ -751,7 +751,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta final Set inactivePressedStates = inactiveStates..add(MaterialState.pressed); final Color effectiveInactivePressedOverlayColor = widget.overlayColor?.resolve(inactivePressedStates) ?? switchTheme.overlayColor?.resolve(inactivePressedStates) - ?? effectiveActiveThumbColor.withAlpha(kRadialReactionAlpha); + ?? effectiveInactiveThumbColor.withAlpha(kRadialReactionAlpha); final MaterialStateProperty effectiveMouseCursor = MaterialStateProperty.resolveWith((Set states) { return MaterialStateProperty.resolveAs(widget.mouseCursor, states) diff --git a/packages/flutter/test/material/switch_test.dart b/packages/flutter/test/material/switch_test.dart index a2d2fad31a..d4595a6ba3 100644 --- a/packages/flutter/test/material/switch_test.dart +++ b/packages/flutter/test/material/switch_test.dart @@ -1552,7 +1552,8 @@ void main() { final FocusNode focusNode = FocusNode(debugLabel: 'Switch'); 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 inactivePressedOverlayColor = Color(0xFF000002); const Color hoverOverlayColor = Color(0xFF000003); @@ -1585,7 +1586,12 @@ void main() { autofocus: focused, value: active, onChanged: (_) { }, - thumbColor: const MaterialStatePropertyAll(thumbColor), + thumbColor: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.selected)) { + return activeThumbColor; + } + return inactiveThumbColor; + }), overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, hoverColor: hoverColor, 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.press(find.byType(Switch)); await tester.pumpAndSettle(); @@ -1604,12 +1611,13 @@ void main() { paints ..rrect() ..circle( - color: thumbColor.withAlpha(kRadialReactionAlpha), + color: inactiveThumbColor.withAlpha(kRadialReactionAlpha), radius: splashRadius, ), 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.press(find.byType(Switch)); await tester.pumpAndSettle(); @@ -1619,12 +1627,13 @@ void main() { paints ..rrect() ..circle( - color: thumbColor.withAlpha(kRadialReactionAlpha), + color: activeThumbColor.withAlpha(kRadialReactionAlpha), radius: splashRadius, ), reason: 'Default active pressed Switch should have overlay color from thumbColor', ); + // test inactive Switch with an overlayColor await tester.pumpWidget(buildSwitch()); await tester.press(find.byType(Switch)); await tester.pumpAndSettle(); @@ -1640,6 +1649,7 @@ void main() { reason: 'Inactive pressed Switch should have overlay color: $inactivePressedOverlayColor', ); + // test active Switch with an overlayColor await tester.pumpWidget(buildSwitch(active: true)); await tester.press(find.byType(Switch)); await tester.pumpAndSettle();