Skip to content

Conversation

@TahaTesser
Copy link
Member

Fixes Discrete Slider and RangeSlider applies thumb padding when using custom Slider shapes

Code Sample

expand to view the code sample
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) {},
            ),
          ],
        ),
      ),
    );
  }
}

Before

Screenshot 2025-03-06 at 13 33 17

After

Screenshot 2025-03-06 at 13 33 28

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 Mar 6, 2025
@TahaTesser TahaTesser marked this pull request as ready for review March 6, 2025 14:26
@TahaTesser TahaTesser requested a review from QuncCccccc March 10, 2025 11:45
Copy link
Contributor

@QuncCccccc QuncCccccc left a 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)
Copy link
Contributor

@QuncCccccc QuncCccccc Mar 11, 2025

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.

Copy link
Member Author

@TahaTesser TahaTesser Mar 12, 2025

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.

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.

Copy link
Contributor

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!

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment

@TahaTesser TahaTesser requested a review from QuncCccccc March 12, 2025 11:23
@TahaTesser TahaTesser force-pushed the fix_sliders_discrete_padding branch 2 times, most recently from 3e364c5 to 3b67573 Compare March 17, 2025 08:22
@QuncCccccc
Copy link
Contributor

The failed Google testing seems related to M2 style.

@TahaTesser
Copy link
Member Author

TahaTesser commented Mar 18, 2025

@QuncCccccc
Thanks! I've pushed which a commit restores like discrete padding the way it was before the this PR and renamed the same discrete padding in RangeSlider to be consistent.

Looks like checks are green. Could you please confirm this fixes the issue you described?

@TahaTesser TahaTesser force-pushed the fix_sliders_discrete_padding branch from 1bb820b to 6a39a39 Compare March 19, 2025 09:32
@QuncCccccc QuncCccccc self-requested a review April 9, 2025 18:27
@QuncCccccc
Copy link
Contributor

Seems the inactive track part has been fixed🎉, but for the active track, I can still see some failures:) Will talk with @TahaTesser offline.

@TahaTesser
Copy link
Member Author

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.

@TahaTesser TahaTesser force-pushed the fix_sliders_discrete_padding branch from 5a412b5 to 77d03b6 Compare April 24, 2025 17:44
@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 29, 2025
Copy link
Contributor

@QuncCccccc QuncCccccc left a 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.

@auto-submit auto-submit bot added this pull request to the merge queue Apr 29, 2025
Merged via the queue into flutter:master with commit b6e964b Apr 30, 2025
76 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
@TahaTesser TahaTesser deleted the fix_sliders_discrete_padding branch May 3, 2025 16:14
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull request Aug 14, 2025
…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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
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.

Discrete Slider and RangeSlider applies thumb padding when using custom Slider shapes

2 participants