Skip to content

Fix Slider label: clipping the screen - #184208

Closed
mbcorona wants to merge 222 commits into
flutter:masterfrom
mbcorona:fix/slider-long-label-63293
Closed

mbcorona wants to merge 222 commits into
flutter:masterfrom
mbcorona:fix/slider-long-label-63293

Conversation

@mbcorona

Copy link
Copy Markdown
Member

This PR addresses the issue where long text in a Slider label clips off the edges of the screen.

Following the discussion in the issue, this limits the label's maxWidth to screenSize.width minus a calculated horizontal buffer (_kValueIndicatorHorizontalBuffer). It also forces maxLines = 1 and applies the standard Material ellipsis (\u2026). This prevents the text from expanding beyond the screen boundaries and prevents the bubble shape from breaking vertically.

I am opening this as a draft to get early feedback from @QuncCccccc on the layout logic before proceeding with tests.

Fixes #63293

Video example:

Screen.Recording.2026-03-26.at.10.35.32.AM.mov

Pre-launch Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Mar 26, 2026

@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.

The fix looks good to me! Could you also help double check whether RangeSlider has the same issue. If so we can fix them together:)! Thank you!


// Buffer to account for the internal padding of standard Material value indicator shapes,
// preventing them from bleeding off the screen edges.
static const double _kValueIndicatorHorizontalBuffer = 64.0;

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.

Where do we get this number?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The 64.0 is a heuristic (32px per side) to prevent the bubble from clipping at the screen edges. Let me know if there's a specific framework constant I should use instead.

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.

I don't think the specs on the website mentioned the value of the paddings. Can we just avoid setting paddings? It's okay that the label edges touches the screen edge as long as they are clipped.

..layout();
..maxLines = 1
..ellipsis =
'\u2026' // Material standard ellipsis

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.

// Material standard ellipsis

Are there any doc or link mentioning this is Material standard?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For the ellipsis, you're right. It's just the standard unicode ellipsis \u2026. I fixed the comment.

@github-actions github-actions Bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos and removed d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels Mar 27, 2026
@mbcorona
mbcorona force-pushed the fix/slider-long-label-63293 branch from 762489a to cc49d6d Compare March 31, 2026 13:43
@mbcorona

Copy link
Copy Markdown
Member Author

Hi @QuncCccccc , yes RangeSlider has same isssue, I also applied the same fix to RangeSlider:

Screen.Recording.2026-03-27.at.8.52.28.AM.mov

@mbcorona
mbcorona marked this pull request as ready for review April 7, 2026 20:12

@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 introduces a horizontal buffer for value indicators in the Slider and RangeSlider widgets to prevent them from overflowing screen edges, and implements single-line label truncation with an ellipsis. The review feedback requests documentation for the 64.0 buffer constant to explain its derivation and suggests wrapping a line in range_slider.dart that exceeds the 80-character limit.


// Buffer to account for the internal padding of standard Material value indicator shapes,
// preventing them from bleeding off the screen edges.
static const double _kValueIndicatorHorizontalBuffer = 64.0;

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.

medium

The constant _kValueIndicatorHorizontalBuffer is set to 64.0, but its derivation is not documented. Please add a comment explaining why 64.0 was chosen (e.g., accounting for typical bubble padding and screen margins). This follows the "Answer your own questions" principle in the repository style guide.

References
  1. Documentation should be useful and explain the 'why'. If a value is chosen, it should be documented where it's defined. (link)

};

// Reserve space for the bubble's internal padding and screen margins.
final double safeMaxWidth = math.max(0.0, screenSize.width - _kValueIndicatorHorizontalBuffer);

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.

medium

This line exceeds the 80-character limit and is inconsistent with the formatting used in slider.dart. Wrapping the math.max call improves readability and adheres to the project's formatting standards.

    final double safeMaxWidth = math.max(
      0.0,
      screenSize.width - _kValueIndicatorHorizontalBuffer,
    );
References
  1. Optimize for readability. All Dart code is formatted using dart format, which typically wraps lines at 80 characters. (link)


// Buffer to account for the internal padding of standard Material value indicator shapes,
// preventing them from bleeding off the screen edges.
static const double _kValueIndicatorHorizontalBuffer = 64.0;

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.

medium

Please add a comment explaining the choice of 64.0 for this buffer, similar to the documentation suggested in range_slider.dart. This ensures maintainability by explaining the reasoning behind the hardcoded value.

References
  1. Documentation should be useful and explain the 'why'. (link)

@QuncCccccc
QuncCccccc self-requested a review April 7, 2026 22:16

@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.

Overall the change makes sense to me. Thank you for your contribution. Please remember to add unit tests for both Slider and RangeSlider:)!


// Buffer to account for the internal padding of standard Material value indicator shapes,
// preventing them from bleeding off the screen edges.
static const double _kValueIndicatorHorizontalBuffer = 64.0;

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.

I don't think the specs on the website mentioned the value of the paddings. Can we just avoid setting paddings? It's okay that the label edges touches the screen edge as long as they are clipped.

..maxLines = 1
..ellipsis =
'\u2026' // Standard Unicode ellipsis
..layout(maxWidth: safeMaxWidth);

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.

Can we just use screenSize.width without setting extra paddings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hey @QuncCccccc, I tried using screenSize.width directly without padding, but it results in the outer bubble clipping at the screen edges. See screenshot:

Screenshot 2026-04-14 at 7 38 53 AM

Is there a different framework convention you'd prefer I use to handle the shape's padding?

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.

Oh I see. I don't think we have such convention but I agree that we should add padding around it.

@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.

I think the fixes makes sense to me! Let's add some unit tests for it and we should be good to go! Thank you!

..maxLines = 1
..ellipsis =
'\u2026' // Standard Unicode ellipsis
..layout(maxWidth: safeMaxWidth);

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.

Oh I see. I don't think we have such convention but I agree that we should add padding around it.

static const double _minPreferredTrackWidth = 144.0;

// Buffer to account for the internal padding of standard Material value indicator shapes,
// preventing them from bleeding off the screen edges.

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.

We can also add some more explanation like:

Suggested change
// preventing them from bleeding off the screen edges.
// preventing them from bleeding off the screen edges.
//
// The value 64.0 is a heuristic that covers the minimum size of the shape
// (padding + minimum label width) at a text scale factor of roughly 2.0.

engine-flutter-autoroll and others added 11 commits April 15, 2026 09:11
…r#184393)

flutter/packages@582f0e7...b04f3e5

2026-03-30 [email protected] [ci] Compares commits before creating a
sync PR to sync release branch back to the main branch.
(flutter/packages#11398)
2026-03-30 [email protected] [ci] Add permission to
release_from_branches.yml (flutter/packages#11397)
2026-03-30 [email protected] [pigeon] Reduces lint rules ignored in
generated Dart code (flutter/packages#11230)
2026-03-30 [email protected] [google_maps_flutter] Add missing
exports (flutter/packages#11196)
2026-03-30 [email protected] [vector_graphic]
docs: corrected width/height description in VectorGraphic
(flutter/packages#11361)
2026-03-30 [email protected] [ci] Uses
fluttergithubbot to create branches and PRs (flutter/packages#11368)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…#184264)

This is a draft that tests removing the fake impeller images workaround
for the iOS simulator, which was originally added in [this
PR](flutter-team-archive/engine#54974)

We've confirmed that this workaround is no longer needed.
…4374)

https://skia.googlesource.com/skia.git/+log/dfd8f8002800..f37239a7a689

2026-03-31 [email protected] [graphite] turn off DrawListLayer caps
flag
2026-03-30
recipe-mega-autoroller@chops-service-accounts.iam.gserviceaccount.com
Roll recipe dependencies (trivial).

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/skia-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on
the revert to ensure that a human
is aware of the problem.

To file a bug in Skia: https://bugs.chromium.org/p/skia/issues/entry
To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This reverts commit 697701b.

This is a manual revert from
flutter#184426. That process seems
broken.
…5406)

Restore and enable IAccessibleEx implementation.
Exposes new features of UI Automation to MSAA-based implementation.
Specifically usefull to expose AutomationId from
SemanticsNode::identifier for UI test automation.

see flutter#148763

Followup to flutter#161955

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

---------

Co-authored-by: Matthew Kosarek <[email protected]>
…flutter#184368)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/fuchsia-gn-sdk-flutter
Please CC [email protected],[email protected] on the
revert to ensure that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This fix has 2 parts basically:

1. Reuse autofill forms. Prior to this PR, the autofill forms were being
recreated every time a text input connection is established. This
behavior prevents Safari from autofilling the entire form. This PR
reuses the existing form and fields instead of recreating them.

2. Re-establish the text input connection with the framework when the
text field receives focus from the browser. This is necessary for
iOS26's new focus behavior where it blurs the text field then focuses it
before autofilling it. That blur-then-focus is a new behavior that was
not accounted for by the web engine.

Fixes flutter#177248

---------

Co-authored-by: Loïc Sharma <[email protected]>
…#184379)

https://dart.googlesource.com/sdk.git/+log/eaeccf98848d..75a089eb6bf9

2026-03-31 [email protected]
Version 3.12.0-304.0.dev

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/dart-sdk-flutter
Please CC [email protected],[email protected] on the revert to
ensure that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…... (flutter#184383)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/fuchsia-linux-sdk-flutter
Please CC [email protected],[email protected] on the revert to ensure that
a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…n test (flutter#184398)

This package will be resolved through the workspace.
@github-actions github-actions Bot added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: internationalization Supporting other languages or locales. (aka i18n) platform-fuchsia Fuchsia code specifically f: scrolling Viewports, list views, slivers, etc. p: cupertino_ui cupertino_ui package in flutter/packages platform-windows Building on or for Windows specifically d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: routes Navigator, Router, and related APIs. platform-web Web applications specifically platform-linux Building on or for Linux specifically a: desktop Running on desktop team-infra Owned by Infrastructure team f: focus Focus traversal, gaining or losing focus f: integration_test The flutter/packages/integration_test plugin e: impeller Impeller rendering backend issues and features requests team-android Owned by Android platform team team-engine Owned by Engine team team-ios Owned by iOS platform team d: docs/ flutter/flutter/docs, for contributors team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team platform-macos labels Apr 15, 2026
@mbcorona

Copy link
Copy Markdown
Member Author

@QuncCccccc Thanks for all the guidance on the tests and padding logic! Since the Material code freeze is now active and the CI is blocking merges here, I am going to close this PR and will open a fresh PR with these exact changes over in the new flutter/packages repository once the migration is complete and contributions are re-opened.

@mbcorona mbcorona closed this Apr 15, 2026
@QuncCccccc

Copy link
Copy Markdown
Contributor

We are still open to contribute. Either way is fine to me. We can still open a PR and when it completes (with tests and enough approvals), we will mark it as a draft, then once the migration is complete, we can directly move all these draft over.

@mbcorona mbcorona mentioned this pull request Apr 16, 2026
10 tasks done
@stuartmorgan-g stuartmorgan-g added platform-macos Building on or for macOS specifically and removed platform-macos labels Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: animation Animation APIs a: desktop Running on desktop a: internationalization Supporting other languages or locales. (aka i18n) a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: docs/ flutter/flutter/docs, for contributors d: examples Sample code and demos e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. f: focus Focus traversal, gaining or losing focus f: integration_test The flutter/packages/integration_test plugin f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages platform-android Android applications specifically platform-fuchsia Fuchsia code specifically platform-ios iOS applications specifically platform-linux Building on or for Linux specifically platform-macos Building on or for macOS specifically platform-web Web applications specifically platform-windows Building on or for Windows specifically team-android Owned by Android platform team team-engine Owned by Engine team team-infra Owned by Infrastructure team team-ios Owned by iOS platform team team-linux Owned by the Linux platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slider label clips the screen