Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
Steps to reproduce
- Create a Slider with:
- min: 1
- max: 10
- divisions: 10
-
Run the app.
-
Tap directly on any lower-half division, example:
- Tap on 3 → value becomes 2
- Tap on 4 → value becomes 3
- Tap on higher values (e.g., 6, 7, 8, 9, 10) → the slider selects the correct value.
Expected results
- Tapping exactly on a division point (e.g., 3 or 4) should select that exact value.
- The slider should not round down unless the tap is closer to the previous division.
Actual results
- When tapping on divisions in the lower half of the range, the slider snaps to the previous value instead of the intended one.
- Only values 6 and above behave correctly and select the exact tapped division.
- The rounding behavior is inconsistent across the range.
Code sample
Code sample
Slider(
min: min.toDouble(),
max: max.toDouble(),
value: _value.toDouble(),
divisions: 10,
label: '$_value',
onChanged: (value) {
setState(() {
_value = value.toInt();
});
},
),Screenshots or Video
Screenshots / Video demonstration
Screen.Recording.2026-03-31.at.17.36.58.mov
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.41.3, on macOS 26.4 25E246 darwin-arm64, locale en-YE)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 26.1)
[✓] Chrome - develop for the web
[✓] Connected device (4 available)
[✓] Network resources
• No issues found!Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
zoepatterson1231-del commentedon Mar 31, 2026
bhpy247 commentedon Mar 31, 2026
Fixed the slider step calculation by correcting the
divisionsvalue. Previously, usingdivisions: 10withmin: 1andmax: 10was causing uneven step values because Flutter calculates each step as(max - min) / divisions, resulting in decimal increments instead of whole numbers. Updated the implementation to usedivisions: max - min, ensuring the slider now moves correctly in proper integer steps from1to10.With your code:
step = (max - min) / divisions
min = 1
max = 10
divisions = 10
So the slider moves like: 1.0, 1.9, 2.8, 3.7, 5.5, 6.4, 7.3, 8.2, 9.1, 10
Rounding this of will become : 1, 2, 3, 4, 6, 6, 7, 8, 9, 10
Correction
min = 1
max = 10
divisions = 9
Slider will move: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
namitbor-cmd commentedon Mar 31, 2026
Mairramer commentedon Mar 31, 2026
@mu7mmd I think it would be better to use:
instead of:
The reason is that
.toInt() simply truncates the decimal part (e.g., 2.99 becomes 2), while.round()rounds to the nearest integer. This helps compensate for small floating-point imprecisions and ensures the correct value is selected when tapping on a division.saurabh-mirajkar commentedon Apr 1, 2026
@mu7mmd Thanks for the detailed report. Labelling for
team-designto investigate further.mu7mmd commentedon Apr 1, 2026
The solution provided by @bhpy247 works, subtracting the max from the min resolves the issue. However, I’m not sure whether this is intended behavior or simply a workaround for an underlying rounding problem. Thank you @bhpy247
dkwingsmt commentedon Apr 1, 2026
This definitely looks like a bug. Feel free to tag me for review if anyone is interested in filing a PR!
QuncCccccc commentedon Apr 7, 2026
I think the behavior you are seeing in sample code is the intended result of the math used:
As @bhpy247 described, the sample code starts from 1 and set the max to 10, the total distance is 9. If we want each step to advance by exactly 1 (yielding integer values), the number of divisions should be 9 instead of 10.
If use 10 divisions, each step becomes 0.9 (resulting in values like 1.0, 1.9, 2.8, 3.7). In the
onChangedcallback, usingvalue.toInt()truncates these values (so 2.8 becomes 2), which causes the inconsistent snapping behavior across the range. To get clean integer steps, we should set divisions: 9 or usevalueinstead ofvalue.toInt().CC @dkwingsmt
Screen.Recording.2026-04-07.at.4.46.45.PM.mov
Fix discrete Slider snapping to wrong value when tapping lower-half t…
Fix discrete Slider snapping to wrong value when tapping lower-half t…
Fix discrete Slider snapping to wrong value when tapping lower-half t…
Fix discrete Slider snapping to wrong value when tapping lower-half t…
QuncCccccc commentedon Oct 9, 2026
As I mentioned above, the behavior is WAI.
github-actions commentedon Oct 23, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.