-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Automatically applied Scrollbars on Desktop in ScrollBehaviors #75354
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
Conversation
|
Still WIP here 🤕 😝 |
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Tests were not as bad as they initially seemed, fixed now. My primary concerns for adding this feature are that
|
|
From a framework user's perspective I think it's concerning that I have to worry about double scrollbars. If this feature is to be implemented I would assume that the framework will handle figuring out if I added a scrollbar explicitly or I am relying on automated scrollbar feature. If this detection is not possible then I would rather not have this feature. Just sharing my opinion, for what it's worth. |
|
Thanks @kunit1, I agree. I'm gathering more feedback as well from the rest of the team.
I don't think we can automatically detect a Scrollbar. They can be placed anywhere in the tree, and even if we could track them all down, we would need to distinguish which were made automatically and which were user generated. In general, I try to avoid automatically making decisions for users like this. |
|
The preceding change has landed, this has been updated and is ready for review. :) |
| /// For example, based on the platform and provided details, this method | ||
| /// could wrap a given widget with a [GlowingOverscrollIndicator] to provide | ||
| /// visual feedback when the user overscrolls. | ||
| Widget buildViewportDecoration( |
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.
@Hixie, you had asked about this signature in the design doc, I created ScrollableDetails as you suggested. I agree it will make this more future proof if we need more information later.
|
Looks like the analyzer is not happy. |
| final AxisDirection direction; | ||
|
|
||
| /// A [ScrollController] that can be used to control the position of the | ||
| /// [Scrollable] widget. |
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.
Document what it means to set this to null or non-null?
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.
Maybe we should even rename this to make it clear that this is the controller for the scrollbar?
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 hesitant to name this as specific to scrollbars, the controller may be used in the future for other things.
| Widget child, | ||
| ScrollableDetails details, | ||
| ) { | ||
| // No GlowingOverscrollIndicator or Scrollbar applied. |
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.
Why no scrollbar? Don't they need one on desktop?
| physics: widget.scrollPhysics, | ||
| dragStartBehavior: widget.dragStartBehavior, | ||
| restorationId: widget.restorationId, | ||
| autoScrollbar: 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.
If this is a multiline textfield, doesn't it need scrollbars to scroll up and down?
| Axis get axis => axisDirectionToAxis(axisDirection); | ||
|
|
||
| /// {@template flutter.widgets.scrollable.autoScrollbar} | ||
| /// Whether a [Scrollbar] should automatically be applied to this Scrollable. |
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 property only takes affect when a controller is also provided, though, right?
|
I thought about this a little more: It seems like we have cases where we want a scrollbar, but not glow (DropDown menu?) and cases where we want a glow, but no scrollbar (PageView). Do we need to disentangle the glow and the scrollbar stuff? Here's an idea I had: We could change the ScrollBehavior class to represent something like the following: class ScrollBehavior {
@protected
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
// current implementation, unchanged, mainly used for glow
}
@protected
Widget buildScrollbars(BuildContext context, Widget child, ScrollableDetails details,) {
// wraps child in scrollbars (or returns the child directly)
}
// Called by the Scrollable instead of buildViewportChrome.
Widget buildViewportDecorations(BuildContext context, Widget child, ScrollableDetails details,) {
return buildViewportChrome(context, buildScrollbars(context, child, details), details.axisDirection);
}
// probably needs a different name?
ScrollBehavior copyWith({bool chrome = true, bool = scrollbars = true}) {
return _WrappedScrollBehavior(this, chrome: chrome, scrollbars: scrollbars);
}
// Other stuff in ScrollBehavior
}The _WrappedScrollBehavior basically forwards all calls to the wrapped instance, except if Furthermore, we change Scrollable to take an optional ScrollBehavior (if it is not provided, it looks one up in the tree like it does today). (This is similar to how it already takes an optional physics param.) Now widgets that don't want scrollbars can pass ScrollConfigoration.of(context).copyWith(scrollbars: false) to the scrollable as behavior. Similar for widgets that don't need a glow. As a bonus: This shouldn't be breaking. Last, but not least, we need to change Scrollable to always have a ScrollController (if none was passed in, it creates one locally) to always pass it to ScrollDetails for the ScrollBehavior (otherwise we wouldn't be able to build the scrollbar). |
|
Hm, let me experiment and see what this would look like. My first impression is that it's a bit complicated, and possibly hard to understand why buildViewportChrome is just for the glow while there are other methods for other decorations. I'll play with this a bit more.. |
|
Closing in favor of #78588 |
Design Document
This change applies
Raw/Cupertino/Scrollbars by default on the Web and Desktop platforms. I've done this in a similar way to how we apply theGlowingOverscrollIndicator, in eachWidget/Material/CupertinoScrollBehavior. This allows us to get the rightScrollbarfor the givenScrollBehavior.This current proposal requires a breaking change toUpdate: Instead I have deprecatedScrollBehavior.buildViewportChrome, adding an optionalcontrollerparameter asScrollbarrequires aScrollControllerfor full functionality.buildViewportChromein favor ofbuildViewportDecoration. Breaking the former was a really hard break, so I have introduced a new method, and added an opt-in flag (ScrollBehavior.useDecoration) so customers can be migrated gracefully.This new method will use (also new)
ScrollableDetailsto ascertain the right decoration. PassingScrollableDetailswill be a bit more future-proof, where if needed we can add to the details rather than needing to change a function signature. The ScrollableDetails currently contains the required AxisDirection (used for the GlowingOverscrollIndicator decoration), and an optional controller. If a controller is not provided, noScrollbarwill be created.Some instances of
Scrollableare excluded from this including:EditableTextListWheelScrollViewPageViewNestedScrollViewScrollBehaviorthat I have, for now, excluded scrollbars from)To give users control over this, I have added the ability to toggle this feature on and off inUpdate: This was a bit over the top, exposing ScrollBehaviors is a cleaner way for users to control defaults. That will be a prerequisite change, in #76739ThemeDataandCupertinoThemeData.Blocked by: #76739Fixes: #40107
Fixes: #70866 (Last part)
Also related as part of ScrollBehavior overhaul: #75728
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.