Skip to content

Slider selects the wrong value when tapping on lower-half divisions #184391

Closed as not planned

Description

@mu7mmd

Steps to reproduce

  1. Create a Slider with:
  • min: 1
  • max: 10
  • divisions: 10
  1. Run the app.

  2. Tap directly on any lower-half division, example:

  • Tap on 3 → value becomes 2
  • Tap on 4 → value becomes 3
  1. 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!

Activity

  1. zoepatterson1231-del commented on Mar 31, 2026

    @zoepatterson1231-del
  2. bhpy247 commented on Mar 31, 2026

    @bhpy247

    Fixed the slider step calculation by correcting the divisions value. Previously, using divisions: 10 with min: 1 and max: 10 was 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 use divisions: max - min, ensuring the slider now moves correctly in proper integer steps from 1 to 10.

    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

  3. namitbor-cmd commented on Mar 31, 2026

    @namitbor-cmd
  4. Mairramer commented on Mar 31, 2026

    @Mairramer
    Contributor

    @mu7mmd I think it would be better to use:

    onChanged: (value) {
      setState(() {
        _value = value.round();
      });
    },

    instead of:

    onChanged: (value) {
      setState(() {
        _value = value.toInt();
      });
    },

    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.

  5. saurabh-mirajkar commented on Apr 1, 2026

    @saurabh-mirajkar
    Contributor

    @mu7mmd Thanks for the detailed report. Labelling for team-design to investigate further.

  6. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Apr 1, 2026
  7. mu7mmd commented on Apr 1, 2026

    @mu7mmd
    Author

    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

  8. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Apr 1, 2026
  9. dkwingsmt commented on Apr 1, 2026

    @dkwingsmt
    Contributor

    This definitely looks like a bug. Feel free to tag me for review if anyone is interested in filing a PR!

  10. QuncCccccc commented on Apr 7, 2026

    @QuncCccccc
    Contributor

    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 onChanged callback, using value.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 use value instead of value.toInt().

    CC @dkwingsmt

    Screen.Recording.2026-04-07.at.4.46.45.PM.mov
  11. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
  12. QuncCccccc commented on Oct 9, 2026

    @QuncCccccc
    Contributor

    As I mentioned above, the behavior is WAI.

  13. github-actions commented on Oct 23, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions