Skip to content

Commit 96a770b

Browse files
authored
[Material] Remove "down position" from toggleable ripple calculation (#112209)
* remove down position from toggleable ripple
1 parent 4beceb8 commit 96a770b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter
559559
focusColor,
560560
reactionFocusFade.value,
561561
)!;
562-
final Offset center = Offset.lerp(downPosition ?? origin, origin, reaction.value)!;
563562
final Animatable<double> radialReactionRadiusTween = Tween<double>(
564563
begin: 0.0,
565564
end: splashRadius,
@@ -568,7 +567,7 @@ abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter
568567
? splashRadius
569568
: radialReactionRadiusTween.evaluate(reaction);
570569
if (reactionRadius > 0.0) {
571-
canvas.drawCircle(center + offset, reactionRadius, reactionPaint);
570+
canvas.drawCircle(origin + offset, reactionRadius, reactionPaint);
572571
}
573572
}
574573
}

packages/flutter/test/material/checkbox_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,38 @@ void main() {
602602
);
603603
});
604604

605+
testWidgets('Checkbox starts the splash in center, even when tap is on the corner', (WidgetTester tester) async {
606+
Widget buildApp() {
607+
return MaterialApp(
608+
theme: theme,
609+
home: Material(
610+
child: Center(
611+
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
612+
return Checkbox(
613+
value: false,
614+
onChanged: (bool? newValue) {},
615+
);
616+
}),
617+
),
618+
),
619+
);
620+
}
621+
622+
await tester.pumpWidget(buildApp());
623+
final Offset checkboxTopLeftGlobal = tester.getTopLeft(find.byType(Checkbox));
624+
final Offset checkboxCenterGlobal = tester.getCenter(find.byType(Checkbox));
625+
final Offset checkboxCenterLocal = checkboxCenterGlobal - checkboxTopLeftGlobal;
626+
await tester.startGesture(checkboxTopLeftGlobal);
627+
await tester.pump();
628+
// Wait for the splash to be drawn, but not long enough for it to animate towards the center, since
629+
// we want to catch it in its starting position.
630+
await tester.pump(const Duration(milliseconds: 1));
631+
expect(
632+
Material.of(tester.element(find.byType(Checkbox))),
633+
paints..circle(x: checkboxCenterLocal.dx, y: checkboxCenterLocal.dy),
634+
);
635+
});
636+
605637
testWidgets('Checkbox can be hovered and has correct hover color', (WidgetTester tester) async {
606638
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
607639
bool? value = true;

0 commit comments

Comments
 (0)