Skip to content

Fix RangeSlider dragged cursor handling.#179988

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
ksokolovskyi:fix-range-slider-dragged-cursor
Jan 14, 2026
Merged

Fix RangeSlider dragged cursor handling.#179988
auto-submit[bot] merged 4 commits into
flutter:masterfrom
ksokolovskyi:fix-range-slider-dragged-cursor

Conversation

@ksokolovskyi

Copy link
Copy Markdown
Contributor

Fixes #179987

Description

  • Fixes dragged cursor handling in RangeSlider
  • Replaces MaterialState occurrences with WidgetState
  • Updates tests to ensure that all cases are covered
Before After
before.mov
after.mov

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Dec 17, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue with dragged cursor handling in RangeSlider. The _handleDragStart and _handleDragEnd methods now call setState to update the _dragging flag, ensuring the widget rebuilds and reflects the correct cursor state. The implementation also replaces MaterialState with WidgetState, including MaterialStatePropertyAll with WidgetStatePropertyAll. Additionally, the test for WidgetStateMouseCursor has been rewritten to be more comprehensive, covering various states like disabled, hovered, and dragged, and using more direct gesture controls.

);
}

await tester.pumpWidget(buildApp(divisions: 3));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change above makes sense to me, but why the test will fail when the divisions stays 3?

@dkwingsmt dkwingsmt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for Qun's question.

@ksokolovskyi

Copy link
Copy Markdown
Contributor Author

Hi @QuncCccccc and @dkwingsmt. Thanks a lot for your reviews!

Regarding the change from divisions: 3 to divisions: 5. The lower division count was causing an unintentional snapping behavior during the test, which triggered additional painting logic.

When divisions: 3 is used, the initial thumb positions do not align perfectly with the discrete divisions. As soon as the test interacts with the slider, the thumbs snap to the nearest division to stay consistent with the discrete intervals.

Screenshot 2026-01-05 at 10 20 09 Screenshot 2026-01-05 at 10 25 47

Once the snap occurs, the thumbs overlap at the same value, and the top thumb receives a white border.

Previously, _handleDragStart and _handleDragEnd did not trigger a setState. With the changes in this PR, a setState is correctly called, which causes the framework to paint that white border.

The paints matcher in the test expects a specific sequence of draw calls.

expect(
  valueIndicatorBox,
  paints
    // Represents the raised button wth next text.
    ..path(color: Colors.black)
    ..paragraph()
    // Represents the range slider.
    ..path(color: fillColor)
    ..paragraph()
    ..path(color: fillColor)
    ..paragraph(),
);

Because of the white border, the actual paint sequence includes an extra ..path(color: Colors.white) that the test wasn't expecting:

Expected sequence (with divisions: 3):

expect(
  valueIndicatorBox,
  paints
    ..path(color: Colors.black) // Button
    ..paragraph()
    ..path(color: fillColor)   // Thumb Path 1
    ..paragraph()
    ..path(color: Colors.white) // <--- The white border path causing the mismatch
    ..path(color: fillColor)   // Thumb Path 2
    ..paragraph(),
);

By switching to divisions: 5, the initial thumb values align perfectly with the discrete steps from the start. This prevents the thumbs' realignment during the first interaction, meaning the white border is never painted, and the original paint expectations remain valid.

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation! LGTM:)

@ksokolovskyi

Copy link
Copy Markdown
Contributor Author

@QuncCccccc thanks a lot for your review!

@ksokolovskyi ksokolovskyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 14, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jan 14, 2026
Merged via the queue into flutter:master with commit 5e417dc Jan 14, 2026
71 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RangeSlider dragged cursor is not visible if onChangeStart and onChangeEnd are not set.

3 participants