-
Notifications
You must be signed in to change notification settings - Fork 3
Create a WidgetTester extension to drag scroll bars (Resolves #22) #23
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
base: main
Are you sure you want to change the base?
Create a WidgetTester extension to drag scroll bars (Resolves #22) #23
Conversation
lib/src/scrollbar.dart
Outdated
/// Simulates the user interacting with a Scrollbar. | ||
extension ScrollbarInteractions on WidgetTester { | ||
/// Press a scrollbar thumb at [thumbLocation] and drag it vertically by [delta] pixels. | ||
Future<void> dragScrollbar(Offset thumbLocation, double delta) async { |
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.
How does the user know where there scrollbar thumb is located?
Also, we should use this in a test in this package to demonstrate that it works, and show how we expect others to use it.
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.
Currently, there is no way to find the thumb. I filed flutter/flutter#161403.
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 if the caller has to provide the thumb location then this doesn't have much value. Can you think of any workaround so that a caller can essentially say "drag the scrollbar 100px down"?
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 only way it would work at the moment is if the thumb sits at the top-right of the widget. If it is at any other place, we cannot know its position.
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.
Can can't make an educated guess? What if we check the associated scroll offset, total content height, and the height of the scrollbar? Wouldn't that tell us where the thumb should be?
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 that, if we want to support, all scrollbar's configurations (vertical x horizontal, LTR x RTL, thumb margin, etc), we probably need most of this 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'd appreciate specificity instead of generalities. In terms of a vertical scrollbar, where does my suggestion fail?
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.
It would fail for situations when there is margin/padding on the scrollbar (although it would be simple to add it to this code), and if it's placed on the left side instead of the right side.
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.
What does it mean for there to be margin/padding on 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.
With margin, the thumb won't use the whole track, there will be an empty space at the edges of the scrollbar.
The padding can be applied to top/bottom/left/right, which means that the thumb might not be placed exactly at the right edge of the scrollable widget.
2ea212d
to
a4e6831
Compare
lib/src/scrollbar.dart
Outdated
/// | ||
/// By default, this method expects a single [Scrollbar] in the widget tree and | ||
/// finds it `byType`. To specify one [Scrollbar] among many, pass a [finder]. | ||
Future<void> dragScrollbar(double delta, [Finder? finder]) async { |
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.
We should make this action even more clear by adding the direction to the method name, e.g., dragScrollbarDown(300)
and dragScrollbarUp(300)
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.
Updated.
Create a WidgetTester extension to drag scroll bars. Resolves #22
Dragging a scrollbar requires hovering over the scroll bar, waiting for it to appear, and then dragging and releasing it.
This PR adds a
dragScrollbar
method yo make it easier to interacting with a scrollbar.We can't use a finder to locate the scrollbar thumb because the scrollbar widget uses a single painter to paint both the scrollbar track and the thumb.
We have a
kTapMinTime
constant in super_editor that we use in the tests. I needed to use the value directly here.