Skip to content

Conversation

@xu-baolin
Copy link
Member

Fixes #89681

If update the _DraggableScrollableSheetScrollPosition during drag will lose _dragCancelCallback, and will trigger an assertion.

@flutter-dashboard flutter-dashboard bot added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels May 9, 2022
@xu-baolin xu-baolin requested a review from Piinks May 9, 2022 11:04
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 know that this will always be true? Since this is private implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this is not always true.
This may be another type of position when the widget type changes.
Make a type check here also cause some tests failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, is there another way we could indicate this? Perhaps a flag?
Using is here is not congruent with the style guide: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-interleaving-multiple-concepts-together

Copy link
Member Author

@xu-baolin xu-baolin May 24, 2022

Choose a reason for hiding this comment

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

oops, seems a bit difficult.
I took a look and here is the only chance to catch old position information.
I agree with the above guidance, but here is just to distinguish whether the old type is consistent with myself, and does not interleave other concepts, I think it is reasonable, what do you think? : )

Copy link
Contributor

Choose a reason for hiding this comment

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

I dunno, tbh I am not very familiar with DraggableScrollableSheet, @dnfield may know more.
All of this is private implementation, so it might be ok to distinguish this case.
What tests failed if the type is assumed to be _DraggableScrollableSheetScrollPosition?

I'll reach out to @Hixie on Discord in case this is a style guide exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked to see what tests failed - mostly 'ScrollPositionWithSingleContext' is not a subtype of type '_DraggableScrollableSheetScrollPosition?' in type cast

(I was adding a type cast in the createPosition function of the controller)

What about adding a copyWith to _DraggableScrollableSheetScrollPosition, that way when it is created, you can copy over any ScrollPosition related info (including subclasses like ScrollPositionWithSingleContext)? Just throwing out ideas.. IIRC the copyWith in ScrollBehavior was due to a similar situation. I saw you landed a fix in that recently by the way - thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

@Piinks Thank you so much for catching this bad smell 😄
I think with your ideas I found the perfect solution.

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! Thank @xu-baolin!

_DraggableSheetExtent get extent => getExtent();

@override
void absorb(ScrollPosition other) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this approach looks much cleaner and easier to follow.

super.absorb(other);
assert(_dragCancelCallback == null);

if (other is! _DraggableScrollableSheetScrollPosition) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This still uses is, but I checked for more clarity on the style guide.
I think this use case is ok since it is specific to this private class in order to maintain functionality.

I found a number of places in the framework where is is used, and i feel like this is one of those cases where it is appropriate.

Brief chat on discord for reference: https://discord.com/channels/608014603317936148/608018585025118217/979083546989838366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

weird log for DraggableScrollableSheet

4 participants