Skip to content

Conversation

@TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Jun 3, 2024

fixes [Slider] Thumb's center doesn't align with division's center
fixes Slider thumb doesn't respect round slider track shape
fixes RoundedRectSliderTrackShape corners are not rendered correctly

(Verified these behaviors with Android components implementation)

Code sample

expand to view the code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _value = 5.0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        sliderTheme: const SliderThemeData(
          trackHeight: 32,
          thumbColor: Colors.green,
          activeTrackColor: Colors.deepPurple,
          inactiveTrackColor: Colors.amber,
        ),
      ),
      home: Scaffold(
        body: Slider(
          value: _value,
          // divisions: 10,
          // ignore: avoid_redundant_argument_values
          min: 0,
          max: 10,
          onChanged: (double value) {
            setState(() {
              _value = value;
            });
          },
        ),
      ),
    );
  }
}

Description

This PR fixes several core Sliders issues which are apparent in #147783. As a result, fixing the these bugs will unblock it.

1. Fixes the thumb doesn't align with Slider divisions.

Group 8

Group 9

2. Fixes RoundedRectSliderTrackShape corners are not rendered correctly.

Group 10

3. Fixes round track shape corners when the thumb is at the start or end of the round track shape.

Group 4

Group 3

Group 7

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 Jun 3, 2024
@TahaTesser TahaTesser force-pushed the fix_slider_issues branch from b53e452 to ffb98aa Compare June 3, 2024 14:54
@TahaTesser TahaTesser mentioned this pull request Jun 3, 2024
9 tasks
@TahaTesser TahaTesser marked this pull request as ready for review June 3, 2024 15:22
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha ffb98aae854a5674a394a9b0978c7ba8b5ea33cd

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Jun 3, 2024
@Piinks
Copy link
Contributor

Piinks commented Jun 3, 2024

Pinging to my inbox so it's in my queue. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we use is a lot in the slider code like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe instead of is, RoundedRectSliderTrackShape and others can contains a getter for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent idea! Added isRounded getter. Please let me know what do you think.

@TahaTesser TahaTesser force-pushed the fix_slider_issues branch from ffb98aa to 8dfa9b4 Compare June 6, 2024 11:49
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha 8dfa9b4

@TahaTesser TahaTesser requested a review from Piinks June 11, 2024 13:43
Copy link
Contributor

@Piinks Piinks 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 @TahaTesser 🙏

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha fe6c6f3

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha cff1bd9

@TahaTesser
Copy link
Member Author

@Piinks
Rebased and even pushed empty commit, it seems Google testing is failing.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha 687c31d

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

The goldens changes look like they're only due to slight changes in the rounded corners of the track (seems expected).

In the Google tests I see a bunch of visual diff tests related to the position of the thumb and sometimes its label (seems expected), but also I see breakages of classes that extends SliderTrackShape.

/// Whether the track shape is rounded.
///
/// This is used to determine the correct position of the thumb in relation to the track.
bool get isRounded;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is is possible to give a default value here? This will break anyone that extends SliderTrackShape.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you!

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha b8f446c

@TahaTesser TahaTesser requested a review from justinmc June 20, 2024 12:15
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha 2095138

@justinmc
Copy link
Contributor

It looks like there are still breakages of classes that use implements with SliderTrackShape because they don't have an implementation of isRounded. I always have to refresh myself on this in Dart, so to be specific:

abstract class Foo {
  bool get isRounded => false;
}

// Error, missing implementation of isRounded (even though Foo has an implementation).
class Bar implements Foo {
}

// No error.
class Baz extends Foo {
}

Some options to move forward here:

  1. Modify this PR so that it does not cause a breakage. It looks doable but I don't know if it would make the code ugly, what do you think?
  2. Keep the PR as-is and migrate all of the broken users, and follow the breaking changes policy. There are 200+ breakages in the Google tests due to this, though I'm guessing the number of places I'd have to add isRounded is not that many. The code change should be straightforward. I think this is doable is we decide to do it.
  3. Keep isRounded, but also make changes to mitigate this kind of breakage in the future. Maybe SliderTrackShape should have been an abstract base class to prevent users from using implements with it (docs on Dart's newish class modifiers)? Maybe we could deprecate SliderTrackShape and move to a new base class without causing an immediate hard breaking change? We would still have to do all of the work from option 2, but this might be better for broken users and better for the long term maintainability of this code.

@Piinks
Copy link
Contributor

Piinks commented Jun 20, 2024

Hmm, maybe we can add a g3 fix in frob to add the getter for folks that have implements? I've also in the past changed the customer's code toe extends temporarily, or permanently if they agree, to unblock changes like these.

@TahaTesser
Copy link
Member Author

TahaTesser commented Jun 25, 2024

Thanks @justinmc!

Modify this PR so that it does not cause a breakage. It looks doable but I don't know if it would make the code ugly, what do you think?

I noticed RoundedRectSliderTrackShape and RectangularSliderTrackShape doesn't override the getPreferredRect from the SliderTrackShape, yet they don't throw an error. This is due to all track shapes using BaseSliderTrackShape mixin with returns a default getPreferredRect.

| updated the PR to return default isRounded in the BaseSliderTrackShape, since the current track shapes are using this mixin, it could be expected the customer's code should be using it too? This solution makes sense since getPreferredRect is already handled this way, and isRounded is just another addition.

Please let me know what do you think.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #149594 at sha 05ee675

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2024
@hauvudinh24
Copy link

hauvudinh24 commented Sep 10, 2024

Hi,
I'm sorry, sir. Will we fix it in the next version of the release?
Thank you.

@TahaTesser
Copy link
Member Author

@hauvudinh24!
This seems to be still on the master channel. It should be eventually make it to the next MAJOR stable release.

github-merge-queue bot pushed a commit that referenced this pull request Dec 9, 2024
…and rounded corners (#159792)

Fixes [`RangeSlider` thumb's center doesn't align with division's
center, thumb padding, and rounded corners don't work as
expected](#159586)

This makes a similar fix as the one for `Slider` in
#149594. This fix is essential to
bring updated Material Design for `RangeSlider`.

### Code sample

<details>
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @OverRide
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _discreetSliderValue = 0.6;
  RangeValues _discreteRangeSliderValues = const RangeValues(0.2, 1.0);

  @OverRide
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        sliderTheme: const SliderThemeData(
          trackHeight: 32,
          thumbColor: Colors.green,
          activeTrackColor: Colors.deepPurple,
          inactiveTrackColor: Colors.amber,
        ),
      ),
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Discrete Slider',
                style: Theme.of(context).textTheme.titleMedium,
              ),
              Slider(
                  value: _discreetSliderValue,
                  divisions: 5,
                  onChanged: (double newValue) {
                    setState(() {
                      _discreetSliderValue = newValue;
                    });
                  }),
              Text(
                'Discrete Range Slider',
                style: Theme.of(context).textTheme.titleMedium,
              ),
              RangeSlider(
                values: _discreteRangeSliderValues,
                divisions: 5,
                onChanged: (RangeValues newValues) {
                  setState(() {
                    _discreteRangeSliderValues = newValues;
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
```

</details>

### Before

<img width="701" alt="Screenshot 2024-12-02 at 18 57 03"
src="https://github.com/user-attachments/assets/62d85476-87fd-48e9-aaa9-42d7629d4808">

### After

<img width="701" alt="Screenshot 2024-12-02 at 18 57 21"
src="https://github.com/user-attachments/assets/36f136d1-a759-4b11-b0a9-8cb6b54b8573">


## 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].
- [ ] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

4 participants