Repository navigation
Commit 2768ebe
Fix discrete Slider snapping to wrong value when tapping lower-half tick marks
Fixes flutter#184391
Two bugs caused discrete Slider taps to land on the wrong division:
1. Coordinate system mismatch: tick marks and the thumb are painted at
`trackLeft + i/d * (trackWidth - padding) + padding/2`, but tap
detection inverted a different, unpadded formula. On rounded tracks
(RoundedRectSliderTrackShape, GappedSliderTrackShape) this pushes
lower-half tap midpoints into the wrong snap bucket. The mismatch is
4 px on M2 and up to 16 px on M3.
Fix: _getValueFromGlobalPosition now uses the same padded formula
when isDiscrete && trackShape.isRounded. The drag-delta normalizer
in _handleDragUpdate is updated to match so tap-then-drag is
consistent.
2. IEEE 754 precision: 0.35 * 10 = 3.4999…9 in double arithmetic, so
.round() returns 3 instead of 4 at the midpoint between ticks 3 and
4. A 1e-10 epsilon guard in _discretize corrects this without biasing
values that are genuinely below the midpoint.
Both fixes are applied to Slider and RangeSlider. Five regression tests
are added to slider_test.dart covering M2 LTR, M3 LTR, RTL, drag
continuity, and the IEEE 754 midpoint case.1 parent cf9e8af commit 2768ebe
3 files changed
Lines changed: 349 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1320 | 1320 | | |
1321 | 1321 | | |
1322 | 1322 | | |
1323 | | - | |
1324 | | - | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
1325 | 1338 | | |
1326 | 1339 | | |
1327 | 1340 | | |
1328 | 1341 | | |
1329 | 1342 | | |
1330 | 1343 | | |
1331 | | - | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
1332 | 1347 | | |
1333 | 1348 | | |
1334 | 1349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
788 | 791 | | |
789 | 792 | | |
790 | 793 | | |
| |||
1577 | 1580 | | |
1578 | 1581 | | |
1579 | 1582 | | |
1580 | | - | |
1581 | | - | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1582 | 1603 | | |
1583 | 1604 | | |
1584 | 1605 | | |
1585 | 1606 | | |
1586 | 1607 | | |
1587 | 1608 | | |
1588 | | - | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
1589 | 1612 | | |
1590 | 1613 | | |
1591 | 1614 | | |
| |||
1661 | 1684 | | |
1662 | 1685 | | |
1663 | 1686 | | |
1664 | | - | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
1665 | 1696 | | |
1666 | 1697 | | |
1667 | 1698 | | |
| |||
0 commit comments