-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix discrete Slider and RangeSlider to enforce thumb height padding when the track shape is non-rounded
#164703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix discrete Slider and RangeSlider to enforce thumb height padding when the track shape is non-rounded
#164703
Conversation
QuncCccccc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. Thanks for the fix. Just a little confused about the numbers in the test.
| material, | ||
| paints | ||
| // Start thumb. | ||
| ..circle(x: sliderPadding, y: 300.0, color: theme.colorScheme.primary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question, how do we get this 24? It looks like sliderPadding isn't used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comes from the track padding applied by base track shape in RangeSlider widget.
Here trackLeft and trackRight are 24 pixels.
flutter/packages/flutter/lib/src/material/slider_theme.dart
Lines 2213 to 2216 in 234b50a
| final double trackLeft = offset.dx + math.max(overlayWidth / 2, thumbWidth / 2); | |
| final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2; | |
| final double trackRight = trackLeft + parentBox.size.width - math.max(thumbWidth, overlayWidth); | |
| final double trackBottom = trackTop + trackHeight; |
I made such track padding customizable in the Slider widget last year (#156143) but it's not yet implemented in RangeSlider but the I used the same wording here "slider padding" since it's effectively the same thing.
I just filed an issue #165046 and assigned. I will complete the Slider padding work for RangeSlider. Thanks for the reminder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see! Could you add a comment above the number? Thanks a lot for the explanation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment
3e364c5 to
3b67573
Compare
|
The failed Google testing seems related to M2 style. |
|
@QuncCccccc Looks like checks are green. Could you please confirm this fixes the issue you described? |
1bb820b to
6a39a39
Compare
|
Seems the inactive track part has been fixed🎉, but for the active track, I can still see some failures:) Will talk with @TahaTesser offline. |
Thanks! I'm pretty stumped since the current code in the PR is just restoring the track padding to the way it was before the original slider padding fix. |
…ng when the track shape is non-rounded
5a412b5 to
77d03b6
Compare
QuncCccccc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for your patience. The Scuba diffs look very small, so I think we should just accept them.
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ng when the track shape is non-rounded (flutter#164703) Fixes [Discrete `Slider` and `RangeSlider` applies thumb padding when using custom Slider shapes](flutter#161805) ### Code Sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const RangeSliderExampleApp()); class RangeSliderExampleApp extends StatelessWidget { const RangeSliderExampleApp({super.key}); @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( sliderTheme: const SliderThemeData( trackHeight: 32, trackShape: RectangularSliderTrackShape(), rangeTrackShape: RectangularRangeSliderTrackShape(), thumbColor: Colors.amber, ), ), home: Scaffold( body: Column( spacing: 20.0, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Slider( value: 100, max: 100, divisions: 100, onChanged: (double value) {}, ), RangeSlider( values: const RangeValues(0, 100), max: 100, divisions: 100, onChanged: (RangeValues values) {}, ), ], ), ), ); } } ``` </details> ### Before <img width="929" alt="Screenshot 2025-03-06 at 13 33 17" src="https://github.com/user-attachments/assets/a089674f-4931-4808-9663-1cd540bf7b11" /> ### After <img width="929" alt="Screenshot 2025-03-06 at 13 33 28" src="https://github.com/user-attachments/assets/77fe5708-f2e4-4734-92c2-46e4d8338d0e" /> ## 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. - [ ] 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]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
…ight padding when the track shape is non-rounded (flutter/flutter#164703)
Fixes Discrete
SliderandRangeSliderapplies thumb padding when using custom Slider shapesCode Sample
expand to view the code sample
Before
After
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.