Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented May 2, 2022

Description

_DraggableScrollableSheetScrollPosition.goBallistic creates new AnimationControllers but doesn’t always dispose them. It disposes AnimationControllers when the animation is stopped or canceled. If the DraggableScrollableSheet is disposed, while some AnimationControllers are running, some Tickers leak.

The solution is similar to the one in #102504

Related Issue

Fixes #101061

Tests

Add one test in draggable_scrollable_sheet_test.dart

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels May 2, 2022
@bleroux bleroux requested a review from dnfield May 2, 2022 08:28
ballisticController.dispose();
if (_ballisticControllers.contains(ballisticController)) {
_ballisticControllers.remove(ballisticController);
ballisticController.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be outside of the if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dnfield
Thanks for reviewing this PR.
In some edge cases (the one in #101061, which is also the one in the test I added with this PR), code in whenCompleteOrCancel might be called after _DraggableScrollableSheetScrollPosition.dispose. If I kept this line outside the if statement it would throw an error about the AnimationController being already disposed.

To avoid this error, I put this line in the if statement and in _DraggableScrollableSheetScrollPosition.dispose I add a call to _ballisticControllers.clear() so if an AnimationController ends just after the call to _DraggableScrollableSheetScrollPosition.dispose it is no more in _ballisticControllers and ballisticController.dispose won’t be called as it is in the if statement. If the AnimationController ends before, it is still in _ballisticControllers and it will be disposed by this line (and removed from _ballisticControllers so we won't try to dispose it again in _DraggableScrollableSheetScrollPosition.dispose)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh ok, thanks, that makes sense.

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.

DraggableScrollableSheet with BouncingScrollPhysics throw exception when closed too fast with scroll

3 participants