From 96a770bda0ecd32ddceab9fdb3313f3f7cd3ec3b Mon Sep 17 00:00:00 2001 From: MH Johnson Date: Fri, 23 Sep 2022 11:50:37 -0400 Subject: [PATCH] [Material] Remove "down position" from toggleable ripple calculation (#112209) * remove down position from toggleable ripple --- .../flutter/lib/src/material/toggleable.dart | 3 +- .../flutter/test/material/checkbox_test.dart | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/toggleable.dart b/packages/flutter/lib/src/material/toggleable.dart index 211d8209f0f..9fc0bb4f98e 100644 --- a/packages/flutter/lib/src/material/toggleable.dart +++ b/packages/flutter/lib/src/material/toggleable.dart @@ -559,7 +559,6 @@ abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter focusColor, reactionFocusFade.value, )!; - final Offset center = Offset.lerp(downPosition ?? origin, origin, reaction.value)!; final Animatable radialReactionRadiusTween = Tween( begin: 0.0, end: splashRadius, @@ -568,7 +567,7 @@ abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter ? splashRadius : radialReactionRadiusTween.evaluate(reaction); if (reactionRadius > 0.0) { - canvas.drawCircle(center + offset, reactionRadius, reactionPaint); + canvas.drawCircle(origin + offset, reactionRadius, reactionPaint); } } } diff --git a/packages/flutter/test/material/checkbox_test.dart b/packages/flutter/test/material/checkbox_test.dart index 3967ab8a918..7230c0d5ebe 100644 --- a/packages/flutter/test/material/checkbox_test.dart +++ b/packages/flutter/test/material/checkbox_test.dart @@ -602,6 +602,38 @@ void main() { ); }); + testWidgets('Checkbox starts the splash in center, even when tap is on the corner', (WidgetTester tester) async { + Widget buildApp() { + return MaterialApp( + theme: theme, + home: Material( + child: Center( + child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { + return Checkbox( + value: false, + onChanged: (bool? newValue) {}, + ); + }), + ), + ), + ); + } + + await tester.pumpWidget(buildApp()); + final Offset checkboxTopLeftGlobal = tester.getTopLeft(find.byType(Checkbox)); + final Offset checkboxCenterGlobal = tester.getCenter(find.byType(Checkbox)); + final Offset checkboxCenterLocal = checkboxCenterGlobal - checkboxTopLeftGlobal; + await tester.startGesture(checkboxTopLeftGlobal); + await tester.pump(); + // Wait for the splash to be drawn, but not long enough for it to animate towards the center, since + // we want to catch it in its starting position. + await tester.pump(const Duration(milliseconds: 1)); + expect( + Material.of(tester.element(find.byType(Checkbox))), + paints..circle(x: checkboxCenterLocal.dx, y: checkboxCenterLocal.dy), + ); + }); + testWidgets('Checkbox can be hovered and has correct hover color', (WidgetTester tester) async { tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; bool? value = true;