You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e244038
Browse filesBrowse the repository at this point in the historyBrowse files
[material_ui] Fix discrete Slider selecting the neighboring tick near the track ends (flutter#12927)
Ports flutter#188012 to `material_ui` now that the Material/Cupertino code freeze has lifted, per the instructions in flutter#188444.
Original PR description:
---
Fixesflutter#194855
Tick marks and the thumb on discrete rounded tracks are *painted* in a padded coordinate space:
```
dx = trackLeft + i/d * (trackWidth − padding) + padding/2
```
where `padding = trackHeight` (4 px on M2's `RoundedRectSliderTrackShape`, up to 16 px on M3's `GappedSliderTrackShape`). But tap detection inverted a different, unpadded formula, so the snap midpoints in tap space diverged from the visual midpoints between tick marks. Lower-half ticks consistently landed in the wrong snap bucket.
Fix: `_getValueFromGlobalPosition` now uses the padded inverse formula when `isDiscrete && trackShape.isRounded`. The drag-delta normalizer in `_handleDragUpdate` is updated to match so a tap followed immediately by a drag is consistent.
Applied to both `Slider` and `RangeSlider`.
## Tests
Added regression tests to `slider_test.dart` and `range_slider_test.dart`. They fail without the fix and pass with it:
- `Slider` snaps at the visual midpoint between every pair of ticks, tapping 0.05px either side of the midpoint, for the default Material 3 track (LTR and RTL) and the gapped track from `Slider.year2023: false` (LTR and RTL), which has the largest padding. Tapping exactly on a tick center can't expose the bug, because the old and new mappings differ by only a couple of pixels there.
- A full-track drag after a tap on a 100-division gapped slider, which covers the drag delta normalizer.
- `RangeSlider` snaps at the visual midpoint between ticks for both thumbs.
- A tick-center sanity check for `Slider`.
All of `slider_test.dart` and `range_slider_test.dart` pass locally.
---
Fixesflutter#194855Closesflutter#188012 (superseded by this PR)
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
0 commit comments