-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for another PR @yiiim!
FYI @TahaTesser who is verry familiar with sliders. :)
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 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 And when we change |
bb3d73d
to
da97b9b
Compare
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.
Great work! Just some initial thoughts.
|
||
OverlayEntry? overlayEntry; | ||
Widget _buildValueIndicator(ShowValueIndicator? showValueIndicator) { | ||
late final Widget valueIndicator = CompositedTransformFollower( |
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.
late final Widget valueIndicator = CompositedTransformFollower( | |
late final Widget valueIndicator = CompositedTransformFollower( |
Is late
required since the value is assigned here.
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.
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.
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.
the late
isn't required to execute this code.
link: _layerLink, | ||
child: _ValueIndicatorRenderObjectWidget(state: this), | ||
); | ||
late final Widget valueIndicatorWhenDragged = ValueListenableBuilder<bool>( |
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.
similarly, late
is used but value is also assigned here.
void hideValueIndicator() { | ||
assert(mounted); | ||
_showValueIndicatorForDragged.value = false; |
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 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.
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.
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
.
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); |
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.
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
?
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.
That's awesome! I completely overlooked that. It cleaned up a lot of code.
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.
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.
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 with some nits
@Deprecated( | ||
'Use ShowValueIndicator.onDrag. ' | ||
'This feature was deprecated after v3.28.0-1.0.pre.', | ||
) |
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.
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.
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.
I will write this in a separate PR.
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.
The dart fix should be included in this PR, not a separate change.
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.
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.
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.
dart fix
is included in this PR.
@yiiim Could you please also update #162223 (comment) with new API changes. |
@Piinks Can you help find out the reason why the Google test failed? |
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.
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.
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.
@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. |
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.
Nit: missing a newline here.
@@ -0,0 +1,35 @@ | |||
# Copyright 2014 The Flutter Authors. All rights reserved. |
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.
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?
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.
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.
b6b9699
to
0fd3f15
Compare
Fixes: #34704
Modified enum
ShowValueIndicator
before:
after:
To maintain previous behavior,
ShowValueIndicator.onlyForDiscrete
andShowValueIndicator.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 withShowValueIndicator.onDrag
. A newShowValueIndicator.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.