Skip to content
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

Allow the Slider to always show the value indicator. #162223

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

yiiim
Copy link
Member

@yiiim yiiim commented Jan 26, 2025

Fixes: #34704

Modified enum ShowValueIndicator
before:

enum ShowValueIndicator {
  onlyForDiscrete,
  onlyForContinuous,
  always,
  never,
}

after:

enum ShowValueIndicator {
  onlyForDiscrete,
  onlyForContinuous,
  @Deprecated(
    'Use ShowValueIndicator.onDrag. '
    'This feature was deprecated after v3.28.0-1.0.pre.',
  )
  always,
  onDrag,
  alwaysVisible,
  never,
}

To maintain previous behavior, ShowValueIndicator.onlyForDiscrete and ShowValueIndicator.onlyForContinuous are still retained.

The behavior of ShowValueIndicator.always remains consistent with the previous implementation, but it is marked as deprecated and should be replaced with ShowValueIndicator.onDrag. A new ShowValueIndicator.alwaysVisible has been added to show the value indicator even when not dragging.

Additionally, the value indicator is now rendered by OverlayPortal.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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 Jan 26, 2025
@yiiim yiiim added the c: new feature Nothing broken; request for a new capability label Jan 27, 2025
@Piinks Piinks self-requested a review January 29, 2025 19:10
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.

Thanks for another PR @yiiim!
FYI @TahaTesser who is verry familiar with sliders. :)

@TahaTesser TahaTesser self-requested a review February 17, 2025 09:23
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

This PR does a fair bit of refactoring to add OverlayPortal, this makes sliders more complex.

We had previous show value indicator behaviors without OverlayPortal. Please provide more details on OverlayPortal addition and benefits.

@yiiim
Copy link
Member Author

yiiim commented Feb 17, 2025

This PR does a fair bit of refactoring to add OverlayPortal, this makes sliders more complex.

We had previous show value indicator behaviors without OverlayPortal. Please provide more details on OverlayPortal addition and benefits.

Now, when ShowValueIndicator changes, it is necessary to update the child on the overlay simultaneously. OverlayPortal can easily achieve this.

And when we change ShowValueIndicator through setState, we cannot insert or remove OverlayEntry during the build phase.

@yiiim yiiim force-pushed the sider_value_indicator branch from bb3d73d to da97b9b Compare February 17, 2025 15:14
@TahaTesser TahaTesser self-requested a review February 19, 2025 16:05
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

Great work! Just some initial thoughts.


OverlayEntry? overlayEntry;
Widget _buildValueIndicator(ShowValueIndicator? showValueIndicator) {
late final Widget valueIndicator = CompositedTransformFollower(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
late final Widget valueIndicator = CompositedTransformFollower(
late final Widget valueIndicator = CompositedTransformFollower(

Is late required since the value is assigned here.

Copy link
Member Author

Choose a reason for hiding this comment

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

If valueIndicator is never accessed, the assignment expression for valueIndicator will not be executed. It is not necessarily required to create it in the subsequent code.

Copy link
Member

Choose a reason for hiding this comment

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

the late isn't required to execute this code.

link: _layerLink,
child: _ValueIndicatorRenderObjectWidget(state: this),
);
late final Widget valueIndicatorWhenDragged = ValueListenableBuilder<bool>(
Copy link
Member

Choose a reason for hiding this comment

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

similarly, late is used but value is also assigned here.

Comment on lines 782 to 784
void hideValueIndicator() {
assert(mounted);
_showValueIndicatorForDragged.value = false;
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure. Once the portal controller is created and assigned to shown, are we disposing it when value indicator is hidden? Considering a screen might have a bunch sliders and each of one of them might create a portal controller without being disposed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean OverlayPortalController? OverlayPortalController does not need to dispose.

The OverlayChild will always be displayed. When ShowValueIndicator is set to be shown during dragging, _showValueIndicatorForDragged controls whether _ValueIndicatorRenderObjectWidget is mounted to the tree within the OverlayChild.

@TahaTesser
Copy link
Member

TahaTesser commented Feb 21, 2025

FYI @LongCatIsLooong on the overlay portal implementation. I was told you're working on something that would help Slider.

@TahaTesser
Copy link
Member

FYI @LongCatIsLooong on the overlay portal implementation. I was told you're working on something that would help Slider.

Here is the PR #163575

late final OverlayPortalController _valueIndicatorOverlayPortalController =
OverlayPortalController()..show();
// Control whether the value indicator is visible only when it needs to be shown during dragging.
late final ValueNotifier<bool> _showValueIndicatorForDragged = ValueNotifier<bool>(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm not familiar with the implementation, but adding the new state variable would probably make the implementation more complicated than checking if the animation status is .dismissed?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's awesome! I completely overlooked that. It cleaned up a lot of code.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

I think I looked into doing that before, the slider theming API could have been much cleaner if we could use inherited widgets, so thanks for converting the implementation to using OverlayPortal! The OverlayPortal change LGTM.

@TahaTesser TahaTesser self-requested a review March 4, 2025 15:29
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

LGTM with some nits

Comment on lines +131 to +134
@Deprecated(
'Use ShowValueIndicator.onDrag. '
'This feature was deprecated after v3.28.0-1.0.pre.',
)
Copy link
Member

Choose a reason for hiding this comment

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

Do you plan to write a dart fix for this deprecation? It'd be best to deprecate this property in a separate PR with dart fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will write this in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The dart fix should be included in this PR, not a separate change.

Copy link
Member

Choose a reason for hiding this comment

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

If the property is deprecated in this PR then dart fix should be included.

Perhaps, I wasn't clear. I suggested to mark it as deprecated and include dart fix in a separate PR so the dart fix can be included with the deprecation.

Copy link
Member Author

Choose a reason for hiding this comment

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

dart fix is included in this PR.

@TahaTesser
Copy link
Member

@yiiim Could you please also update #162223 (comment) with new API changes. isDragged is now onDrag for instance.

@yiiim
Copy link
Member Author

yiiim commented Mar 6, 2025

@Piinks Can you help find out the reason why the Google test failed?

@yiiim yiiim requested a review from Piinks March 6, 2025 07:34
@TahaTesser TahaTesser self-requested a review March 11, 2025 18:03
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

I just realised I approved it without making sure deprecation mark was reverted after @Piinks comment.

Please include dart fix in this PR if you plan to keep deprecation mark.

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.

@yiiim it looks like the Google testing shows the on tap functionality is broken by this change. When the slider is tapped on, it shows the value indicator in response. Can you take a look?

constant: 'onDrag'
inEnum: 'ShowValueIndicator'

# Before adding a new fix: read instructions at the top of this file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: missing a newline here.

@@ -0,0 +1,35 @@
# Copyright 2014 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure we need a new file just for one fix, can we just add this to the fixes in fix_material.yaml?

Copy link
Contributor

Choose a reason for hiding this comment

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

Dart fixes also need to be tested. Can you please add tests under the test_fixes directory? They demonstrate the code before and after the tool applies the migration.

@github-actions github-actions bot added the c: tech-debt Technical debt, code quality, testing, etc. label Mar 18, 2025
@yiiim yiiim force-pushed the sider_value_indicator branch from b6b9699 to 0fd3f15 Compare March 19, 2025 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: tech-debt Technical debt, code quality, testing, etc. 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.

Flutter slider should have the feature to show value indicator all the time, not just while gesturing
4 participants