Let cupertino & material switches move to the right state after dragging#51606
Conversation
c3ccc03 to
5b23150
Compare
|
@Afsar-Pasha thanks for pointing that out! I disabled curve switching for explicit animations (those not triggered by |
|
LGTM Also the current behavior is a little different |
|
Should be ready for review now. |
c4203f8 to
ba3d673
Compare
ba3d673 to
f940983
Compare
| positionController.reverse(); | ||
| _needsPositionAnimation = true; | ||
|
|
||
| if (position.value >= 0.5 != value) |
|
|
||
| bool get isInteractive => widget.onChanged != null; | ||
|
|
||
| // A non-null boolean value that indicates whether the user has stopped dragging |
There was a problem hiding this comment.
Changed to true at the end of a drag if the switch must be animated to the position indicated by the widget's value.
| @override | ||
| void didChangeDependencies() { | ||
| super.didChangeDependencies(); | ||
| textDirection = Directionality.of(context); |
There was a problem hiding this comment.
Don't think there's any value in caching this value

Description
This pull request makes Cupertino/Material switches move their thumbs to the correct side after a drag gesture. The
onChangedcallback is called when the drag gesture ends at a position that indicates the switch should change its value (which is consistent with the onTap behavior, making them both callonChangedwhen the user reveals the intent to change the value. However this may be a breaking change).For example, with the below switch:
If the thumb is dragged to
true(which is still doable), it will animate back tofalsewhen the user lets go.In addition to that, it also moves
CupertinoSwitch's gestures/animation logic to its state from the render object.Related Issues
Fixes #46046
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.